List R:通过检查引用集从列表生成数据帧
我的同事萨曼莎问了一个不清楚的问题,所以我在这里问这个问题。 她有一个变量List R:通过检查引用集从列表生成数据帧,list,r,loops,dataframe,List,R,Loops,Dataframe,我的同事萨曼莎问了一个不清楚的问题,所以我在这里问这个问题。 她有一个变量goterms,包含要分析的所有数据帧 goterms <- c('df1','df2','df3') xx2是一个比较集。xx2变量包含所有可能的ILMN编号的子集 xx2 <- c("ILMN_1691487", "ILMN_1716446", "ILMN_1769383","ILMN_1832921") x <- c("ILMN_1665132", "ILMN_1691487", "ILMN_1
goterms
,包含要分析的所有数据帧
goterms <- c('df1','df2','df3')
xx2
是一个比较集。xx2
变量包含所有可能的ILMN编号的子集
xx2 <- c("ILMN_1691487", "ILMN_1716446", "ILMN_1769383","ILMN_1832921")
x <- c("ILMN_1665132", "ILMN_1691487", "ILMN_1716446", "ILMN_1769383", "ILMN_1772387",
"ILMN_1783910", "ILMN_1784863","ILMN_1651599", "ILMN_1652693", "ILMN_1652825",
"ILMN_1653324", "ILMN_1655595","ILMN_1656057", "ILMN_1659077", "ILMN_1659923",
"ILMN_1659947", "ILMN_1662322","ILMN_1662619", "ILMN_1664565", "ILMN_1665132",
"ILMN_1665738", "ILMN_1665859","ILMN_1661695", "ILMN_1665132", "ILMN_1716446",
"ILMN_1737314", "ILMN_1772387","ILMN_1784863", "ILMN_1796094", "ILMN_1800317",
"ILMN_1800512", "ILMN_1807074")
对于所有这些变量,目标是检查每个goterm
,以及相应的ILMN代码(如果它们位于参考集xx2
)。为了检查这一点,使用match函数,所有不匹配项都给出0,匹配值替换为1。为了方便地概述所有的goterms
实验,我想创建一个如下的循环,检查参考集x
中的每个基因。最终结果必须是一个data.frame
,用于比较data.frame
中每个goterm
的结果
test <- list()
for (i in 1:length(goterms)) {
goilmn <- as.data.frame(interestedGO[i])
resultILMN <- match(goilmn[,1], xx2, nomatch=0)
resultILMN[resultILMN!=0] <- 1
result <- cbind(goilmn, resultILMN)
colnames(result) <- c('x', 'result')
zz <- merge(result, x, all=TRUE)
zz[is.na(zz)] <- 0
test[[i]] <- matrix(resultloop)
}
有人能帮我吗?
谢谢 这对你有用吗
data.frame(code=x, sapply(interestedGO, function(curdf){
ifelse(x %in% xx2, x %in% curdf, 0)
}))
+很好。我正在研究类似的方法,但您的解决方案非常紧凑。
1 ILMN_1651599 0 0 0
2 ILMN_1652693 0 0 0
3 ILMN_1652825 0 0 0
4 ILMN_1653324 0 0 0
5 ILMN_1655595 0 0 0
6 ILMN_1656057 0 0 0
7 ILMN_1659077 0 0 0
8 ILMN_1659923 0 0 0
9 ILMN_1659947 0 0 0
10 ILMN_1661695 0 0 0
11 ILMN_1662322 0 0 0
12 ILMN_1662619 0 0 0
13 ILMN_1664565 0 0 0
14 ILMN_1665132 0 0 0
15 ILMN_1665132 0 0 0
16 ILMN_1665132 0 0 0
17 ILMN_1665738 0 0 0
18 ILMN_1665859 0 0 0
19 ILMN_1691487 0 0 1
20 ILMN_1716446 1 0 1
21 ILMN_1716446 1 0 1
22 ILMN_1737314 0 0 0
23 ILMN_1769383 0 0 1
24 ILMN_1772387 0 0 0
25 ILMN_1772387 0 0 0
26 ILMN_1783910 0 0 0
27 ILMN_1784863 0 0 0
28 ILMN_1784863 0 0 0
29 ILMN_1796094 0 0 0
30 ILMN_1800317 0 0 0
31 ILMN_1800512 0 0 0
32 ILMN_1807074 0 0 0
data.frame(code=x, sapply(interestedGO, function(curdf){
ifelse(x %in% xx2, x %in% curdf, 0)
}))