Skip to content
Prev 284995 / 398502 Next

Counting occurences of variables in a dataframe

On Feb 11, 2012, at 1:17 PM, Kai Mx wrote:

            
>  ave(unclass(kdate), knames, FUN=order )
  [1] 2 2 1 1 1 2 1 2 1 1


That was actually not using the dataframe values but you could also do  
this:

 > kdata$ord <- with(kdata, ave(unclass(kdate), knames, FUN=order ))
 > kdata
    knames      kdate ord
1      ab 2011-10-01   2
2      aa 2011-11-02   2
3      ac 2010-10-01   1
4      ad 2010-03-15   1
5      ab 2010-12-01   1
6      ac 2011-01-05   2
7      aa 2010-10-01   1
8      ad 2011-05-04   2
9      ae 2011-06-03   1
10     af 2011-02-01   1
David Winsemius, MD
West Hartford, CT