获取相关结果(r和p)后如何更改列表[[]]名称
我有一个数据,我用lappy循环计算了数据帧中一个基因和另一个基因之间的相关性 现在,总结果存储在一个列表中。下一步我想通过基因符号提取一个结果,如下所示:Correlation.list[[“gene symbol”]] 但结果仅显示使用编号:Correlation.list[[1]] 以下是我的示例数据和代码:获取相关结果(r和p)后如何更改列表[[]]名称,r,lapply,R,Lapply,我有一个数据,我用lappy循环计算了数据帧中一个基因和另一个基因之间的相关性 现在,总结果存储在一个列表中。下一步我想通过基因符号提取一个结果,如下所示:Correlation.list[[“gene symbol”]] 但结果仅显示使用编号:Correlation.list[[1]] 以下是我的示例数据和代码: data_logg<-structure(c(6.05572382866802, 11.1380021588504, 9.3044407551291, 7.871239801
data_logg<-structure(c(6.05572382866802, 11.1380021588504, 9.3044407551291,
7.87123980178745, 10.1452025129037, 8.93954331139168, 7.72897302870656,
8.31753461010792, 6.91902649139208, 8.81063297295094, 22.5569750353369,
31.520979452157, 28.3261317078564, 25.402957920785, 35.8148569235307,
27.8723220522029, 41.0335341398849, 28.5846501726903, 21.398001509988,
33.063696558847, 15.182913110301, 14.6438943008441, 16.1624032499377,
13.1264245066984, 13.4072656803608, 14.7364553246895, 13.1211732101273,
14.3003714459557, 14.918175412959, 15.7912093225492, 0.0931714621767618,
0.0303852980725358, 0.0114778232990823, 0.0260809645231031, 0,
0.0310539968593767, 0.019047166325137, 0.0105050244811974, 0.0264828042698263,
0.0346757324524723, 3.46286706915552, 4.99156437489882, 5.70180521646014,
4.0868441874337, 4.51377652615602, 5.35554484236395, 5.44397291505049,
6.57811217176637, 5.10097757787774, 5.18489532380933, 1.12546006270081,
1.91823256736007, 1.8500381393557, 1.4401998592, 1.14712309386819,
1.63756861783462, 1.63809356500207, 1.99896249233356, 1.3388769544766,
2.07437306868356, 1.5068638533804, 2.63183788279904, 3.12822707867838,
2.44752756389731, 2.37001697139819, 2.51118444838866, 3.48267851492631,
3.26267014874084, 1.75288566197561, 2.80059464803222, 21.3209507790769,
22.6744418461091, 16.9622647095367, 22.2902884855603, 25.7854403101755,
20.6976499521803, 24.1019869113154, 24.764924561036, 22.8547950562338,
15.9953039663019), .Dim = c(10L, 8L), .Dimnames = list(NULL,
c("Zzef1", "Zyx", "Zyg11b", "Zyg11a", "Zxdc", "Zxdb", "Zxda",
"Zwint")))
data\u loggCorrelation\u list
没有名称,因此无法使用Correlation.list[[“基因符号”]]
提取数据
这里有两个选择-
将名称分配到lappy
循环之后的Correlation\u list
然后可以使用基因名称提取相关数据
Correlation_list[["Zwint"]]
#Same as
#Correlation_list$Zwint
# Zwint_Correlaiton Zwint_P_value
#Zzef1 -0.030303030 0.93377296
#Zyx 0.284848485 0.42503815
#Zyg11b -0.733333333 0.01580060
#Zyg11a -0.660606061 0.03758838
#Zxdc -0.006060606 0.98674291
#Zxdb -0.260606061 0.46708905
#Zxda 0.006060606 0.98674291
@YBS,我不知道你是否熟悉我的问题。???你能想象我脸上的问号吗。嗯,就几分钟你就给了我答案。感谢你。谢谢
names(Correlation_list) <- colnames(data_logg)
Correlation_list<- sapply(colnames(data_logg),function(ii){
i<-match(ii,colnames(data_logg))
# i<-ii %in% colnames(data_logg)
tm <- psych::corr.test(data_logg[,i,drop=FALSE],
y = data_logg[,-i], use = "pairwise", "spearman", adjust="none",
alpha=0.05, ci=F, minlength=5)
res<-t(do.call(rbind, tm[c("r", "p")]))
# res$r<-signif(res$r,3) ## 3位小数点后
# res$p<-signif(res$p,3) ## 3位有效数字
colnames(res)<- c(paste0(ii,"_Correlaiton"), paste0(ii,"_P_value"))
na.omit(res)
}, simplify = FALSE)
Correlation_list[["Zwint"]]
#Same as
#Correlation_list$Zwint
# Zwint_Correlaiton Zwint_P_value
#Zzef1 -0.030303030 0.93377296
#Zyx 0.284848485 0.42503815
#Zyg11b -0.733333333 0.01580060
#Zyg11a -0.660606061 0.03758838
#Zxdc -0.006060606 0.98674291
#Zxdb -0.260606061 0.46708905
#Zxda 0.006060606 0.98674291