我有一个 test_list
test_list <- list("hg38:Chr12:8823762", "hg38:Chr10:50814012", "hg19:Chr12:8990070",
"hg38:chr1:16949", "hg38:chr9:342484")
我想检查我的列表中的每个元素部分我的专栏匹配Extra_information
的df
df <- structure(list(Extra_information = c("hg38:Chr10:50814012, hg19:Chr10:52573772, CpG:Mutation may have occured by deamination of methylated CpG dinucleotide",
"hg38:Chr12:8822661, hg19:Chr12:8975257, COM:Patient is homozygous for c.706C>G p.Leu236Val in SLC26A4., dbSNP:http://www.ncbi.nlm.nih.gov/SNP/snp_ref.cgi?type=rs&rs=rs1409944554",
"hg38:Chr12:8823729, hg19:Chr12:8976325, COM:Variant of unknown significance. Clinical features descr. in supplementary table 2. functional study., dbSNP:http://www.ncbi.nlm.nih.gov/SNP/snp_ref.cgi?type=rs&rs=rs766201825",
"hg38:Chr12:8823762, hg19:Chr12:8976358, COM:VUS Table 2. RIT1 variant also present.",
"hg38:Chr12:8835642, hg19:Chr12:8988238, COM:VUS Table 2. SOS1 and CBL variants also present., dbSNP:http://www.ncbi.nlm.nih.gov/SNP/snp_ref.cgi?type=rs&rs=rs11047499",
"hg38:Chr12:8837474, hg19:Chr12:8990070, dbSNP:http://www.ncbi.nlm.nih.gov/SNP/snp_ref.cgi?type=rs&rs=rs863224952"
)), row.names = c(NA, 6L), class = "data.frame")
获得我的列表中,其中值的数据帧1
的TRUE
和0
为FALSE
:
test_df <- structure(list(Entries = c("hg38:Chr12:8823762", "hg38:Chr10:50814012", "hg19:Chr12:8990070",
"hg38:chr1:16949", "hg38:chr9:342484"), Values = c(1,1,1,0,0)), row.names = c(NA, 5L), class = "data.frame"))
如何获得所需的输出?
提前致谢。
我们可以agrepl
用来检查'test_list'元素和'Extra_information'之间的部分匹配(base R
仅来自)
Values <- +(sapply(test_list, function(x) any(agrepl(x, df$Extra_information))))
data.frame(Entries = unlist(test_list), Values)
# Entries Values
#1 hg38:Chr12:8823762 1
#2 hg38:Chr10:50814012 1
#3 hg19:Chr12:8990070 1
#4 hg38:chr1:16949 0
#5 hg38:chr9:342484 0
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句