I'm trying to import a text file into R, specifically the spatstat package. I've loaded a shp file as the window and that worked just fine (displays with plot() ). I can't get the ppp() command to run though. I keep getting this error after running pp <- ppp(X, Y, window=W)

Error in ppp(X, Y, window = W) : 
  1 out of 904 coordinate values are NA or NaN

I've double-checked the file and neither of the X or Y coords have any blank numbers or even negative numbers.

What should I check to deal with this error? Also, this data is public so I can give it to anybody if they need to have a look at it.

有帮助吗?

解决方案

It would be better to check the dataset loaded from the file rather than the file itself. There can be a lot of tricky things in the txt that are hard to catch by eye, a space delimiter instead of a tab, an extra '\n' at the end, etc.

Try a

which(is.nan(X))

It looks like there's just one observation giving you a problem.

其他提示

I would something like this :

ok <- is.finite(X) & is.finite(Y)
if(!ok){
    X <- X[is.finite(X)]
    Y <- Y[is.finite(Y)]
}
pp <- ppp(X, Y, window=W)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top