基于与列表匹配的子集 Dataframe

wqsoz72f  于 2023-05-26  发布在  其他
关注(0)|答案(1)|浏览(145)

如果probeID列与coMeth_ls列表中的cg*项之一匹配,我希望对distal.results.stratified.model.1 Dataframe 进行子集化。我的代码返回空数据框。

distal.dmr.cpgs.1a <- distal.results.stratified.model.1a[
  sapply(
    strsplit(distal.results.stratified.model.1a$probeID, ' '), 
    function(x) any(x %in% coMeth_ls)), ]

数据:

> dput(distal.results.stratified.model.1a[1:3,1:3])
structure(list(regionID = c("chr1:1355332-1355333", "chr1:15934516-15934517", 
"chr1:15934516-15934517"), probeID = c("cg03324138", "cg01522970", 
"cg01522970"), target = c("ENSG00000162576", "ENSG00000065526", 
"ENSG00000065526")), row.names = c(NA, 3L), class = "data.frame")

> dput(coMeth_ls[1:10])
list(`chr1:2250410-2250796` = c("cg03324138", "cg02237208", "cg00567930"
), `chr1:2886792-2886868` = c("cg01977798", "cg00050294", "cg04080530"
), `chr1:8271997-8272277` = c("cg02847588", "cg00590817", "cg06780032"
), `chr1:10895950-10896004` = c("cg02971581", "cg09510180", "cg00944431"
), `chr1:12600225-12600529` = c("cg07586026", "cg07242540", "cg00003578"
), `chr1:16553267-16553456` = c("cg03969515", "cg03522107", "cg02987928"
), `chr1:19665131-19665240` = c("cg09356672", "cg05348366", "cg04928049"
), `chr1:23003462-23003569` = c("cg01795776", "cg09062638", "cg02623028"
), `chr1:28573736-28573940` = c("cg05045517", "cg03226554", "cg07148744", 
"cg07913096"), `chr1:29460817-29461070` = c("cg06155303", "cg09264065", 
"cg08597839", "cg00107241"))
z9smfwbn

z9smfwbn1#

不完全确定你想要什么,但如果你想选择distal.results.stratified.model.1a的行,其中probeID匹配列表coMeth_ls的任何子元素,那么用途:

distal.results.stratified.model.1a[
  distal.results.stratified.model.1a$probeID %in% unlist(coMeth_ls), ]

              regionID    probeID          target
1 chr1:1355332-1355333 cg03324138 ENSG00000162576

相关问题