R:匹配数据帧并过滤这些数据帧
我有一个数据帧,比如变量k。“所有可能的名称”列包含ILMN代码的更多标识符。 现在我想在列中搜索所有可能的名称,以查找数据帧标识符中可用的标识符R:匹配数据帧并过滤这些数据帧,r,filter,match,dataframe,R,Filter,Match,Dataframe,我有一个数据帧,比如变量k。“所有可能的名称”列包含ILMN代码的更多标识符。 现在我想在列中搜索所有可能的名称,以查找数据帧标识符中可用的标识符 z <- matrix(c(0,0,1,1,0,0,1,1,0,0,0,0,1,0,1,1,0,1,1,1,1,0,0,0,"RND1 | AB849382 | uc001aeu.1","WDR | AB361738 | uc001aif.1", "PLAC8 | AB271612 | uc001amd.1","TYBSA | AB859482
z <- matrix(c(0,0,1,1,0,0,1,1,0,0,0,0,1,0,1,1,0,1,1,1,1,0,0,0,"RND1 | AB849382 | uc001aeu.1","WDR | AB361738 | uc001aif.1", "PLAC8 | AB271612 | uc001amd.1","TYBSA | AB859482","GRA | AB758392 | uc001aph.1","TAF | AB142353"), nrow=6,
dimnames=list(c("ILMN_1651838","ILMN_1652371","ILMN_1652464","ILMN_1652952","ILMN_1653026","ILMN_1653103"),c("A","B","C","D","all_possible_names")))
k<-as.data.frame(z)
search<-c("AB361738","RND1", "LIS")
identifier <- as.data.frame(search)
创建此数据帧后,可以创建最终输出。列名只能包含以uc0开头的命名
最终结果将是:
search Names
1 AB361738 uc001aif.1
2 RND1 uc001aeu.1
3 LIS NA
有人能帮我吗
非常感谢,,
Lisanne也许不是最好的方法,但有一种方法:
firstStep<-lapply(srch, grep, k$all_possible_names, fixed=TRUE, value=TRUE)
res<-lapply(firstStep, function(subres){
prts<-unlist(strsplit(subres, " | ", fixed=TRUE))
prts[which(substr(prts, 1, 3)=="uc0")]
})
第一步
firstStep<-lapply(srch, grep, k$all_possible_names, fixed=TRUE, value=TRUE)
res<-lapply(firstStep, function(subres){
prts<-unlist(strsplit(subres, " | ", fixed=TRUE))
prts[which(substr(prts, 1, 3)=="uc0")]
})