如何使用“ $”提取r中的字符数据?

时间:2019-07-24 15:13:47

标签: r loops variables

我尝试编写一个循环,但是基因是字符:PDCD1和CD274。如果我用 survdata2 [[indication]] $ PDCD1,它起作用。但是,如果我使用以下方式,则无法正常工作。有什么办法可以做到这一点。

> gene
[1] "CD274"
> survdata2[[indication]]
   Cohort Survival_days Treatment   Status PDCD1 CD274
1     SCC     1469 days      Both Deceased   low   low
2     SCC      759 days     Radio Deceased  high  high
3     SCC      183 days     Radio Deceased   low   low
4     SCC     1566 days     Radio Deceased  high   low
5     SCC     1361 days     Radio Deceased  high   low
6     SCC     1772 days      Both Deceased  high   low
7     SCC     1388 days     Radio Deceased   low   low
8     SCC     2005 days      Both Deceased  high  high
9     SCC     1543 days     Radio Deceased  high  high
10    SCC      357 days      Both Deceased   low  high
11    SCC     1829 days      Both Deceased  high  high
> survdata2[[indication]]$gene
NULL

如果您想知道,我想进行生存分析,我的循环基本上是这样的,但由于以下原因而没有用:

genelist<- c("PDCD1", "CD274")
for (gene in genelist){
.... skip indication part......

 survfit(Surv(survdata2[[indication]]$Survival_days, survdata2[[indication]]$Status=="Deceased")~survdata2[[indication]]$gene)
}

0 个答案:

没有答案