对于hallmark.df
的每一行,如果rownames(all.deg)
匹配给定行的任何值,则检索all.deg
的相应行。我还希望只保留hallmark.df
Dataframe 中非NA列多于25个且列少于500个的行
subset.df <- by(hallmark.df, seq_len(nrow(hallmark.df)), function(row)
ifelse(all.deg[rownames(all.deg) %in% hallmark.df,]))
字符串
输入:all.deg
> dput(all.deg[1:5,1:5])
structure(c(16.0169585624867, 14.3983080662428, 12.7844219145156,
12.6674945373237, 13.8584047354367, 13.563719599839, 13.6166993468069,
12.9748157402651, 12.7386065050292, 12.2201616898331, 11.3657998135948,
11.8253392160132, 12.1132082166185, 11.5123143882139, 10.2967924742924,
13.7513874043739, 13.2403954818698, 12.4196432226432, 12.4676109090624,
12.1390647972695, 12.3013113392588, 12.4867673484914, 11.3693921877853,
10.6359730348998, 10.0122721528039), dim = c(5L, 5L), dimnames = list(
c("JUNB", "ALDOA", "HLA.A", "THBD", "CD74"), c("TCGA.2K.A9WE.01",
"TCGA.2Z.A9J1.01", "TCGA.2Z.A9J3.01", "TCGA.2Z.A9J6.01",
"TCGA.2Z.A9J7.01")))
> dput(hallmark.df[1:5,1:5])
structure(list(V3 = c("JUNB", "PGK1", "FDPS", "ARHGEF2", "CD74"
), V4 = c("CXCL2", "PDK1", "CYP51A1", "CLASP1", "CTNNB1"), V5 = c("ATF3",
"GBE1", "IDI1", "KIF11", "JAG2"), V6 = c("NFKBIA", "PFKL", "FDFT1",
"KIF23", "NOTCH1"), V7 = c("ALDOA", "JUNB", "DHCR7", "ALS2",
"DLL1")), row.names = c("HALLMARK_TNFA_SIGNALING_VIA_NFKB", "HALLMARK_HYPOXIA",
"HALLMARK_CHOLESTEROL_HOMEOSTASIS", "HALLMARK_MITOTIC_SPINDLE",
"HALLMARK_WNT_BETA_CATENIN_SIGNALING"), class = "data.frame")
型
预期产量:HALLMARK_TNFA_SIGNALING_VIA_NFKB
| | TCGA.2K.A9WE.01 | TCGA.2Z.A9J1.01 | TCGA.2Z.A9J3.01 | TCGA.2Z.A9J6.01 | TCGA.2Z.A9J7.01 |
| --|--|--|--|--| ------------ |
| 16.0169585624867| 13.563719599839| 11.3657998135948| 13.7513874043739| 12.3013113392588| 12.3013113392588 |
| 13.8584047354367| 12.2201616898331| 10.2967924742924| 12.1390647972695| 10.0122721528039| 10.0122721528039 |HALLMARK_WNT_BETA_CATENIN_SIGNALING
| | TCGA.2K.A9WE.01 | TCGA.2Z.A9J1.01 | TCGA.2Z.A9J3.01 | TCGA.2Z.A9J6.01 | TCGA.2Z.A9J7.01 |
| --|--|--|--|--| ------------ |
| 14.3983080662428| 13.6166993468069| 11.8253392160132| 13.2403954818698| 12.4867673484914| 12.4867673484914 |
| 16.0169585624867| 13.563719599839| 11.3657998135948| 13.7513874043739| 12.3013113392588| 12.3013113392588 |
df.list <- list(HALLMARK_TNFA_SIGNALING_VIA_NFKB, HALLMARK_WNT_BETA_CATENIN_SIGNALING)
型
相关问题:How to subset a dataframe based on matches to another dataframe?
2条答案
按热度按时间5lhxktic1#
我们可以将行名称转换为列,然后通过{tidyverse}很容易就可以完成:
字符串
创建于2023-07-18,使用reprex v2.0.2
lskq00tm2#
这可能不是解决问题的“最佳”方法,但这里有一个潜在的解决方案:
字符串
创建于2023-07-18,使用reprex v2.0.2
编辑1
要保留hallmark.df数据框中非NA列超过25列且少于500列的行,您可以用途:
型