【发布时间】:2022-01-18 22:09:43
【问题描述】:
共 38 列。 数据代码示例:
df <- structure(
list(
Christensenellaceae = c(
0.010484508,
0.008641566,
0.010017172,
0.010741488,
0.1,
0.2,
0.3,
0.4,
0.7,
0.8,
0.9,
0.1,
0.3,
0.45,
0.5,
0.55
),
Date=c(27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,28),
Treatment = c(
"Treatment 1",
"Treatment 1",
"Treatment 1",
"Treatment 1",
"Treatment 2",
"Treatment 2",
"Treatment 2",
"Treatment 2",
"Treatment 1",
"Treatment 1",
"Treatment 1",
"Treatment 1",
"Treatment 2",
"Treatment 2",
"Treatment 2",
"Treatment 2"
)
),class = "data.frame",
row.names = c(NA,-9L)
)
我想做的是为每列(治疗和日期除外)在治疗类型(总共 10 个,但示例中为 2 个)之间创建肯德尔相关矩阵(数据没有线性行为),因此总共有 36 个相关矩阵尺寸为 1010(此处为 22)。
这是我的代码:
res2 <- cor(as.matrix(data),method ="kendall")
但我得到了错误:
Error in cor(data, method = "kendall") : 'x' must be numeric
有什么办法可以解决这个问题吗?谢谢:)
【问题讨论】:
标签: r matrix correlation