[R] crosstabulation and unlist function
dwinsemius at comcast.net
Mon Oct 12 21:25:07 CEST 2009
On Oct 12, 2009, at 2:36 PM, eugen pircalabelu wrote:
> Hello R-users,
> My toy example:
> Can anyone point me to what function let's me do a crosstabulation
> between table(unlist(df[,1:3])) and df$dd?
> I want to find out when dd==A (or B, or C) how many times do the
> values 1, 2 ,3,.. appear in df[,1:3]?
> Thank you very much!
One way would be to collect the row sums of those columns first, and
then sum by index:
tapply(apply(df[,1:3],1,sum, na.rm=TRUE), df$dd, sum)
A B C
14 9 10
David Winsemius, MD
West Hartford, CT
More information about the R-help