[R] getting an aggregate count, and adding it to a dataset as a new column

From: t c <quantpm_at_yahoo.com>
Date: Wed 19 Oct 2005 - 05:45:37 EST

I have the data below in a dataset called “test3”.  

What is the easiest way to get a count, by date, of all numerical values of var1, and to then add this count to the “test3 “dataset as a new “column”?  

What I have:  

date,var1,cat

1/1/2005,5,a

1/1/2005,12,a

1/1/2005,44,b

2/1/2005,1,b

2/1/2005,8,a

2/1/2005,32,z

2/1/2005,44,a

3/1/2005,5,z

3/1/2005,7,e

3/1/2005,95,s

3/1/2005,95,s

1/1/2005,NA,NA

1/1/2005,4,NA

1/1/2005,5,NA

3/1/2005,NA,NA

4/1/2005,NA,a  

what I want:  

date,var1,cat,n

1/1/2005,5,a,5

1/1/2005,12,a,5

1/1/2005,44,b,5

2/1/2005,1,b,4

2/1/2005,8,a,4

2/1/2005,32,z,4

2/1/2005,44,a,4

3/1/2005,5,z,4

3/1/2005,7,e,4

3/1/2005,95,s,4

3/1/2005,95,s,4

1/1/2005,NA,NA,5

1/1/2005,4,NA,5

1/1/2005,5,NA,5

3/1/2005,NA,NA,4

4/1/2005,NA,a,0                     


        [[alternative HTML version deleted]]



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Oct 19 05:52:57 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 19:03:08 EST