0
votes

Error in [.data.frame(meuse@data, , x) : undefined columns selected

MWE:

library(automap)
data(meuse)
coordinates(meuse) = ~ x+y
lapply(1:1, function (x) {
    automap::autofitVariogram(meuse@data[, x] ~ 1, input_data = meuse)
})

Executing meuse@data[,1] outside the lapplycall works fine and returns a numeric vector.

Also automap::autofitVariogram(meuse@data[, 1] ~ 1, input_data = meuse) runs fine.

Hence I expected it the problem to be caused by the lapply call. However, using another dataset of mine (SpPointsDaFr) does not cause the problem and runs fine.

Looking at the error message more closely, I am not sure if the second "comma" after "meuse@data," is always present in 'subset' error messages?

Edit:

Another approach which does not work: Addressing via string (note that I only use [1:1] instead of [1] for further function use)

cols <- names(meuse@data) [1:1]
> lapply(cols, function (x) {
+     automap::autofitVariogram(meuse@data[, x] ~ 1, input_data = meuse)
+ })
1
Would lapply(... meuse@data[[x]]~1 ... work? - gung - Reinstate Monica
no, returns Error in .subset2(x, i, exact = exact) : no such index at Level 1 - pat-s

1 Answers

0
votes

I found a workaround. Addressing/subsetting the required values of meuse before the call of autofitVariogram and then putting the object tmp in works.

lapply(1:1, function (x) {
        tmp <- meuse@data[, x]
        emp.svgm <- automap::autofitVariogram(tmp ~ 1, meuse)
})

The error when trying to subset inside the function call is still open for discussion though.