Re: [R] how to count unique observations by variables

2008-10-16 Thread Chuck Cleland
On 10/16/2008 1:27 AM, Lijiang Guo wrote: > Dear R-helpers, > > I have a data frame with 3 variables, each record is a unique combination of > the three variables. I would like to count the number of unique values of v3 > in each v1, and save it as a new variable v4 in the same data frame. > e.g.

Re: [R] how to count unique observations by variables

2008-10-15 Thread ronggui
How about this: > df1=data.frame(v1=c(1,1,2,3,2,4,1)) > df1$v2 <- ave(df1$v1,df1$v1,FUN=length) > df1 v1 v2 1 1 3 2 1 3 3 2 2 4 3 1 5 2 2 6 4 1 7 1 3 On Thu, Oct 16, 2008 at 1:27 PM, Lijiang Guo <[EMAIL PROTECTED]> wrote: > Dear R-helpers, > > I have a data frame with 3 variables

Re: [R] how to count unique observations by variables

2008-10-15 Thread David Winsemius
On Oct 16, 2008, at 1:27 AM, Lijiang Guo wrote: Dear R-helpers, I have a data frame with 3 variables, each record is a unique combination of the three variables. I would like to count the number of unique values of v3 in each v1, and save it as a new variable v4 in the same data frame. e.

[R] how to count unique observations by variables

2008-10-15 Thread Lijiang Guo
Dear R-helpers, I have a data frame with 3 variables, each record is a unique combination of the three variables. I would like to count the number of unique values of v3 in each v1, and save it as a new variable v4 in the same data frame. e.g. df1 [v1] [v2] [v3] [1,] "a" "C" "1" [2,] "b" "