I do have a list of elements in
ab
,ab <- list("M","O","E","P","Q","S","T","N","V","R")
In other list
tb
, is a list of 2*2 tables like,Sample data set,
n <- c("M", "N", "O") tb <- lapply(1:10, function(i)matrix(sample(4), 2, 2, dimnames=list(n[sample(3,2)], n[sample(3,2)]))) names(tb) <- paste(1:10)
We only need to filter those tables in which the rowname of 1st table in the list
tb
has 1st element in the listab
, 2nd table has 2nd element and so on. The number of elements in both lis开发者_运维技巧tab
andtb
are the same.How will I match the rownames of the tables in the list with the list of elements?
> is.in <- vector(len=length(ab))
> for(i in 1:length(ab) ) { is.in[i] <- ab[i] %in% rownames(tb[[i]])}
> is.in
#[1] TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
Most of those ab-letters were not in the NMO list so I just checked to see if I were missing some:
> tb[[8]] N M
O 1 4
M 2 3
But ab[8] = "N" is not in the rownames of tb[[8]]
精彩评论