[R] frequency table for a list matching some conditions

Olga Lyashevska olga at herenstraat.nl
Thu Aug 26 11:47:56 CEST 2010


Dear all,

I have a list that contains 3 sublists( x1, x2, x3)

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"))
mylist
$x1
[1] "A" "A" "A" "B" "C" "Z" "Y"

$x2
[1] "D" "D" "E" "E" "F" "Z" "X"

$x3
[1] "A" "A" "A" "B" "Y" "Z"

I also have another list, that contains some specific elements.
newlist<-c("A","B","C","D","E","F")
newlist
[1] "A" "B" "C" "D" "E" "F"

I want to match mylist[1], mylist[2], etc with newlist and I am looking for the following output:

	A  B  C  D  E  F
x1	3  1  1  NA NA NA
x2	NA NA NA 2  2  1
x3	3  1  NA NA NA NA

Any thoughts?

Many thanks 
Olga



More information about the R-help mailing list