在数据框上使用 as.ppp 创建标记的进程

using as.ppp on data frame to create marked process

我正在使用数据框使用 as.ppp 函数创建标记点过程。我收到一个错误 Error: is.numeric(x) is not TRUE。我使用的数据如下:

dput(head(pointDataUTM[,1:2]))

structure(list(POINT_X = c(439845.0069, 450018.3603, 451873.2925, 
446836.5498, 445040.8974, 442060.0477), POINT_Y = c(4624464.56, 
4629024.646, 4624579.758, 4636291.222, 4614853.993, 4651264.579
)), .Names = c("POINT_X", "POINT_Y"), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame"))

我可以看到前两列是数字,所以我不知道为什么这是一个问题。

> str(pointDataUTM)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   5028 obs. of  31 variables:
 $ POINT_X      : num  439845 450018 451873 446837 445041 ...
 $ POINT_Y      : num  4624465 4629025 4624580 4636291 4614854 ...

然后我也检查了NA,显示没有NA

> sum(is.na(pointDataUTM$POINT_X))
[1] 0
> sum(is.na(pointDataUTM$POINT_Y))
[1] 0

当我只尝试 data.frame 的前两列时,我在使用 as.ppp 时遇到的错误是:

Error: is.numeric(x) is not TRUE
5.stop(sprintf(ngettext(length(r), "%s is not TRUE", "%s are not all TRUE"), ch), call. = FALSE, domain = NA)
4.stopifnot(is.numeric(x))
3.ppp(X[, 1], X[, 2], window = win, marks = marx, check = check)
2.as.ppp.data.frame(pointDataUTM[, 1:2], W = studyWindow)
1.as.ppp(pointDataUTM[, 1:2], W = studyWindow)

有人能告诉我这里的错误是什么以及为什么我会收到非数字错误吗?

谢谢。

我在 phone,所以无法检查,但我认为它会发生,因为你有一个 tibble 而不是 data.frame。请先尝试使用 as.data.frame 转换为 data.frame。

关键检查是 PointDataUTM[,1] 是否为数字,而不是 PointDataUTM$POINT_X

由于 PointDataUTM 是一个 tbl 对象,而 tbldplyr 包中的一个函数,可能发生的情况是 tbl class 在提取单个列时返回数据框,而不是数字向量。而 $ 运算符 returns 是一个数字向量。

我建议您在调用 as.ppp 之前使用 as.data.frame() 将数据转换为 data.frame

spatstat 的下一个版本中,我们将使我们的代码更健壮以应对此类问题。