我正在努力加快以下任务:
# 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
?)函数
2-组织数据以便与ggplot2
包一起使用的最佳方法是什么。
感谢您的帮助!
答案 0 :(得分:1)
您可以尝试在感兴趣的列中使用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)