[R] frequency table for a list matching some conditions
Olga Lyashevska
olga at herenstraat.nl
Thu Aug 26 12:48:29 CEST 2010
Thanks Dimitris,
It works nicely!
Regards,
Olga
On Thu, 2010-08-26 at 11:55 +0200, Dimitris Rizopoulos wrote:
> one way is the following:
>
> mylist <- list(x1 = c("A","A","A","B","C","Z","Y"),
> x2 = c("D","D","E","E","F","Z","X"),
> x3 = c("A","A","A","B","Y","Z"))
> newlist <- c("A","B","C","D","E","F")
>
>
> tab <- t(sapply(mylist, function (x)
> table(factor(x, levels = newlist))))
> tab[tab == 0] <- NA
> tab
More information about the R-help
mailing list