我正在尝试加速以下任务:
# For retrieving Cancer Genome Atlas RNAseq data
library(RTCGA.rnaseq)
# Extract information from sample ID about what kind of samples are in the dataset. 01 means tumor, 06 means metastatic tumor, 10 means healthy etc.
SKCM_sampletype <- as.factor(substr(x = SKCM.rnaseq$bcr_patient_barcode, 14, 15))
summary(SKCM_sampletype)
01 06
1 367
# Other objects I like to apply this function are (I have 30some objects but showing few below:
# (ACC.rnaseq,BLCA.rnaseq,BRCA.rnaseq,CESC.rnaseq,CHOL.rnaseq,COAD.rnaseq)我想要做的是拥有一段代码,它将遍历一系列对象并执行substring和summary函数。我还想将所有的summary统计数据组合在一起,并绘制成如下所示的图形:

我的主要问题与两个要点有关: 1-如何编写loop (或apply?)将使用objects的函数2-组织数据的最佳方法是什么,以便与ggplot2包一起轻松使用。
谢谢你的帮助!
发布于 2018-06-02 07:33:34
您可以尝试跨感兴趣的列使用lapply,例如:
summarise_column <- function(x) {
cat(x)
summary(factor(substr(SKCM.rnaseq[[x]], 14, 15)))
}
lapply(c("the", "variables", "I", "would", "like", "to", "summarise"), summarise_column)https://stackoverflow.com/questions/50651655
复制相似问题