gpt4 book ai didi

r - : 'x' must be a numeric matrix 的热图错误

转载 作者:行者123 更新时间:2023-12-04 11:05:34 26 4
gpt4 key购买 nike

我知道这个问题可能会重复,但我尝试了在这个论坛上发布的一些解决方案但没有成功,这就是我在这里发布的原因。

让我们从我的数据集开始,使其可重现。

dataset <- structure(list(Comparison = c("SH vs SAP", "SH vs NEA", "SH vs ERE", 
"SH vs ERH", "SH vs NAL", "SAP vs NEA", "SAP vs ERE", "SAP vs ERH",
"SAP vs NAL", "NEA vs ERE", "NEA vs ERH", "NEA vs NAL", "ERE vs ERH",
"ERE vs NAL", "ERH vs NAL"), DC1 = c(NA, NA, NA, NA, NA, 1, 1,
1, NA, 1, 1, NA, 1, NA, NA), DC2 = c(NA, NA, NA, NA, NA, 1, 1,
1, NA, 0, 0, NA, 1, NA, NA), DC3 = c(1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 0, 0, 1, 0, 1), DC4 = c(1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
0, 1, 1, 1), DC5 = c(0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1,
1), DC6 = c(0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1), DC7 = c(0,
1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1), DC8 = c(0, 1, 0, 1,
1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1), DC9 = c(0, 0, 0, 0, 1, 0, 0,
0, 0, 0, 1, 1, 0, 0, 0), DC10 = c(1, 1, 0, 1, 1, 0, 0, 0, 0,
0, 1, 0, 1, 0, 0)), .Names = c("Comparison", "DC1", "DC2", "DC3",
"DC4", "DC5", "DC6", "DC7", "DC8", "DC9", "DC10"), class = "data.frame", row.names = c(NA,
15L))

我试图将数据集更改为矩阵,正如其他帖子中所建议的那样。但是,它不断给出相同的错误
heatmap(dataset)
heatmap(as.matrix(dataset))

Error in heatmap(dataset) :
'x' must be a numeric matrix

Error in heatmap(as.matrix(dataset)) :
'x' must be a numeric matrix

我试图将列转换为数字,但错误仍然存​​在。当我删除包含 DC1 值的 DC2NA 列时,情况也是如此。

任何帮助发现问题?

最佳答案

dataset[, 1] 是字符所以 as.matrix(dataset) 字符 矩阵。这说明:

'x' must be a numeric matrix



你可能想要
heatmap(as.matrix(dataset[, -1]))

enter image description here

And how can I include the names of the rows on the right?



Comparison 变量设置为矩阵的 rownames:
m <- as.matrix(dataset[, -1])
rownames(m) <- dataset$Comparison
heatmap(m)

enter image description here

所以你真正的问题是 Convert the values in a column into row names in an existing data frame in R 虽然问题是用 heatmap 提出的。

关于r - : 'x' must be a numeric matrix 的热图错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51618315/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com