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)
+ })
lapply(... meuse@data[[x]]~1 ...work? - gung - Reinstate MonicaError in .subset2(x, i, exact = exact) : no such index at Level 1- pat-s