我創建了一個類似下面的循環來檢查與表中的行匹配的條件。如果它們匹配,則打印出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