gpt4 book ai didi

r - 在contour() 中没有指定正确的 'z' 矩阵

转载 作者:行者123 更新时间:2023-12-01 00:57:48 24 4
gpt4 key购买 nike

我试图在 R 中做一个简单的等高线图,但我收到以下错误 "no proper 'z' matrix specified" .
以下是我的代码:

r=read.table("test.dat")
dim(r)
## [1] 56 3

x=matrix(unlist(r[,3]),ncol=112,byrow=T)
dim(x)
## [1] 1 11

image((1:nrow(x))-56,(1:ncol(x))-56,x)
contour((1:nrow(x))-56,(1:ncol(x))-56,x , add=TRUE)

## Error in contour.default((1:nrow(x)) - 56,
## (1:ncol(x)) - 56, x, add = TRUE) :
## no proper 'z' matrix specified

有人可以帮助我哪里出错了。

最佳答案

contour.default的代码(您可以通过在 R 控制台的提示符处键入函数名称来打印)包含以下行:

 if (!is.matrix(z) || 
nrow(z) <= 1L ||
ncol(z) <= 1L)
stop("no proper 'z' matrix specified")

... 换句话说, contour()拒绝尝试处理只有单行或单列的矩阵。这真的是你打算策划的吗?如果是这样,也许您可​​以更全面地解释上下文?

关于r - 在contour() 中没有指定正确的 'z' 矩阵,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29834030/

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