Re: [R] sum variable as long condition is true

2007-10-23 Thread John Kane
aggregate(c$a, list(b=b), sum) --- marcg <[EMAIL PROTECTED]> wrote: > Hello R > > For expierienced user, the following problem will be > easy to solve: > > a<-c(0,1,0,1,0,2,3,4,3,2) > b<-c(3,3,3,4,4,4,7,7,7,10) > c<-data.frame(a,b) > > Data Frame c contains tow colums. I would like to > sum

Re: [R] sum variable as long condition is true

2007-10-23 Thread Shubha Vishwanath Karanth
rowsum(c$a,c$b) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of marcg Sent: Tuesday, October 23, 2007 5:22 PM To: [EMAIL PROTECTED] Subject: [R] sum variable as long condition is true Hello R For expierienced user, the following problem will be easy to

Re: [R] sum variable as long condition is true

2007-10-23 Thread Chuck Cleland
marcg wrote: > Hello R > > For expierienced user, the following problem will be easy to solve: > > a<-c(0,1,0,1,0,2,3,4,3,2) > b<-c(3,3,3,4,4,4,7,7,7,10) > c<-data.frame(a,b) > > Data Frame c contains tow colums. I would like to sum up all values in a as > long as b stays the same: > > sum(a[w

[R] sum variable as long condition is true

2007-10-23 Thread marcg
Hello R For expierienced user, the following problem will be easy to solve: a<-c(0,1,0,1,0,2,3,4,3,2) b<-c(3,3,3,4,4,4,7,7,7,10) c<-data.frame(a,b) Data Frame c contains tow colums. I would like to sum up all values in a as long as b stays the same: sum(a[which(b==1)]) does this, but i have t