r-spatial / gstat

Spatial and spatio-temporal geostatistical modelling, prediction and simulation
http://r-spatial.github.io/gstat/
GNU General Public License v2.0
195 stars 49 forks source link

Fix variogramST.STIDF #135

Open darentsai opened 8 months ago

darentsai commented 8 months ago

https://github.com/r-spatial/gstat/blob/8335d8e2fb1a16b02d256148d502a7edcff9142a/R/variogramST.R#L234

With a moderately large data and unspecified twindow, tmpInd will have countless rows, and apply on it is literally time-consuming. I adapt it for a vectorized computation and the efficiency is much improved.


https://github.com/r-spatial/gstat/blob/8335d8e2fb1a16b02d256148d502a7edcff9142a/R/variogramST.R#L255-L256

data[indSp[,1],1] extracts only one column. For a data.frame, the default is to drop if only one column is left, and the result reduces to a vector. However, for a tibble, it's not the default. data[indSp[,1],1] is still a tibble, and hence passing a tibble into mean returns NA. I add drop=TRUE to coerce tibble to drop.