【发布时间】:2016-03-16 07:57:59
【问题描述】:
我是 R 的初学者,我在尝试在 R 中创建迭代 cor.test 时遇到了一些问题。我有一个包含 8 个不同采样点(第 1 到 8 列)的表,对于每个采样点,我测量了一个变量(VARIABLE1,第一行)和一系列物种的存在(行上的 OTU)。在这里您可以看到我的表格的摘录(称为“矩阵”):
row.names 1 2 3 4 5 6 7 8
VARIABLE1 1565 1809,83 1019 1909,83 756,33 631,67 529,83 436
OTU1 0 0 0 0 0 3 0 0
OTU2 0 0 0 0 0 0 13 0
OTU3 5 0 0 0 0 0 0 0
OTU4 0 0 0 0 0 0 0 0
OTU5 0 0 0 0 0 0 0 2
OTU6 0 0 19 0 9 236 59 2
OTU7 0 0 0 2 4 2 3 0
OTU8 0 0 10 5 0 0 7 0
OTU9 6 0 13 2 0 0 17 6
OTU10 0 0 0 0 0 3 0 0
OTU11 4 13 0 0 2 1 2 0
OTU12 0 0 0 0 0 101 1 0
我想计算 VARIABLE1 与每个 OTU 之间的 spearman 相关性。所以 VARIABLE1 必须保持固定,而 OTU 必须每次都改变。
我尝试使用“lapply”,但没有成功:
flip_matrix <- t(matrix)
variable1 <- flip_matrix[,1]
lapply(flip_matrix[1:107], function(x) cor.test(x, variable1, alternative='two.sided', method='spearman'))
Error in cor.test.default(x, shoot_growth, alternative = "two.sided", :
'x' e 'y' must be of the same length
我该如何解决这个问题?谢谢大家!!
【问题讨论】:
标签: r matrix statistics iteration correlation