我创建了一个类似下面的循环来检查与表中的行匹配的条件。如果它们匹配,则打印出rowname。如果它们不匹配,则不会发生任何事情。将表的多行匹配到多个条件
condition <- c(0,0,1,1)
id <- apply(table, 1,
function(i) sum(i[1:length(table)] != condition)==0)
idd<-as.matrix(id)
for (i in 1:length(idd)){
if (idd[i] == TRUE) {
print(rownames(idd)[i])
}
}
> table
> [1] [2] [3] [4]
>1651838 1 1 0 0
>1653006 0 0 0 0
>1656415 0 0 0 1
>1657317 -1 0 0 0
我的问题是:是否有可能使这个循环的多个条件?例如:
condition <- c("0,0,0,0","0,0,0,1","0,0,1,0","0,1,0,0","1,0,0,0",
"0,0,1,1","1,1,0,0","0,1,1,0","1,0,0,1","1,0,1,0",
"0,1,0,1","1,0,1,1","1,1,0,1","1,1,1,0","0,1,1,1","1,1,1,1")
for(r in 1:length(condition)){
id <- apply(regulationtable, 1,
function(i) sum(i[1:length(regulationtable)] != condition[r])==0
)
idd<-as.matrix(id)
test<-list()
for (i in 1:length(idd)) {
if (idd[i] == TRUE) {
print(rownames(idd)[i])
}
test[[i]]<-matrix(idtest)
}
}
谢谢!
看起来非常相似的措词http://stackoverflow.com/questions/5375642/venndiagram-create-list-of-venncounts – 2011-03-22 10:26:37