Skip to content
Prev 361643 / 398506 Next

summing up and cut off with looping

Hi Brent;
I do appreciate for your helps and advice. I already registered online to learn R. Today my second day. I think I could not explain my problem precisely. I have two file called A and B. A has to columns say posA and posB the values of the first row in A are 1 and 9, and?the values of the second row in A 2 and 7. In file B however I have pos, a, b,c columns, for example.? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? pos a ? b ? ? c?The first row of ? ? ? ? ? ? ? ? ?B ? ?4 ? ? 0.4 ? ?0.80the second column of the B ? ? 2 ? ? 0.1 ? 0.40
The third column of ? ? ? ? ?B ? ?13 ? ?0.5 ? ?0.32?
So?I would like to sum up the B$a column and cut off at 0.7 for the each row of intervals giving in file=A. ?Once again thanks so much.
regards,
Oslo
Here are my codes
#sorting B$possort=B[order(B$pos),]
#Running loop
for(i in 1:nrow(A)) {if(sum(B[a$B, i:A[1:2])>0.7) {print(A[1:i,]) } }
On Friday, June 10, 2016 3:44 PM, Bert Gunter <bgunter.4567 at gmail.com> wrote:
1. Please read the posting guide (link below) to learn how to post
understandable questions -- at least I was not able to understand. In
particular, post in plain text, not html, which tends to get mangled
as seemed to occur here.

2. Your first stop in learning R should be one of the many fine
tutorials available on the web or even the "Intro to R" tutorial that
ships with R.? In particular, indexing in R using logical expressions
appears relevant to your query. Here is an example of what can be done
along the lines that I think you asked about -- hope it helps.
Apologies if I have misunderstood. See also ?subset and ?cumsum .
[1] 0.36751828 0.08721951 0.08899027 0.38838635 0.33331978 0.72948251
 [7] 0.36669151 0.28457792 0.90614056 0.31832515
[1] 0.36751828 0.08721951 0.08899027 0.38838635


Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Fri, Jun 10, 2016 at 12:27 PM, oslo via R-help <r-help at r-project.org> wrote: