[R] unique column values and counts

topman77 at yahoo.com topman77 at yahoo.com
Tue Nov 30 01:40:51 CET 2010


How do I create a second dataframe that shows unique column values from first dataframe and the number count of rows in first dataframe where column value appears?

For example, first dataframe is this:

>  x <- matrix(c(101:104,101:104,105:106,1:10), nrow=10, ncol=2)
> x
      [,1] [,2]
 [1,]  101    1
 [2,]  102    2
 [3,]  103    3
 [4,]  104    4
 [5,]  101    5
 [6,]  102    6
 [7,]  103    7
 [8,]  104    8
 [9,]  105    9
[10,]  106   10
> 

>From above dataframe I would like to generate count summary dataframe:

      id    count
 [1,]  101    2
 [2,]  102    2
 [3,]  103    2
 [4,]  104    2
 [5,]  105    1
 [6,]  106    1


Thanks for the help,  Ted



More information about the R-help mailing list