Re: [R] partially sum variable of a dataframe

2007-11-07 Thread Julian Burgos
I'm assuming that you want to add b if 33 & a<5.25]) This is very simple R coding. I recommend you spend some time learning the basics. There are very good tutorials at the R website. Julian [EMAIL PROTECTED] wrote: > Hello, > > A stupid question: > > I have an array with two columns, the f

Re: [R] partially sum variable of a dataframe

2007-11-07 Thread Bert Gunter
Or even simpler (when cc is a data frame), instead of sum(cc[cc[,"a"] <= 5.25 & cc[,"a"] >= 3, "b"]) ## with(cc, sum(b[a <= 5.25 & a >= 3])) Bert Gunter Genentech Nonclinical Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/ma

Re: [R] partially sum variable of a dataframe

2007-11-07 Thread Bert Gunter
PROTECTED] Sent: Wednesday, November 07, 2007 9:02 AM To: [EMAIL PROTECTED] Cc: r-help@r-project.org Subject: Re: [R] partially sum variable of a dataframe There's probably a shorter way but below works and doesn't require the starting points to be in the a column. startindex<-3 endi

Re: [R] partially sum variable of a dataframe

2007-11-07 Thread markleeds
There's probably a shorter way but below works and doesn't require the starting points to be in the a column. startindex<-3 endindex<-5.25 start<-tail(which(c$a<=startindex),1) end<-tail(which(c$a<=endindex),1) sum(c$b[start:end]) >Hello, > >A stupid question: > >I have an array with two colum

Re: [R] partially sum variable of a dataframe

2007-11-07 Thread John Kane
d <- subset(c, c$a > 3 & c$a < 5.25 ) sum(d[,2]) --- [EMAIL PROTECTED] wrote: > Hello, > > A stupid question: > > I have an array with two columns, the first "a" > acting as my index in 0.25 steps, the second one "b" > the column of interest. How can i sum up "b" only > for a specified window i

[R] partially sum variable of a dataframe

2007-11-07 Thread mdgi
Hello, A stupid question: I have an array with two columns, the first "a" acting as my index in 0.25 steps, the second one "b" the column of interest. How can i sum up "b" only for a specified window in "a" (as the window command for time series) a=seq(0,10,0.25) b=runif(41) c=data.frame(a,b)

Re: [R] partially sum variable of a dataframe

2007-11-07 Thread jim holtman
sum(c$b[(c$a > 3) & (c$a < 5.25)]) On 11/7/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > Hello, > > A stupid question: > > I have an array with two columns, the first "a" acting as my index in 0.25 > steps, the second one "b" the column of interest. How can i sum up "b" only > for a specifi