Skip to content

Conversation

darentsai
Copy link

tmpInd[,3] <- apply(tmpInd[,1:2,drop=FALSE], 1, function(x) spDists(data@sp[x[1]], data@sp[x[2]+x[1],]))

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.


gstat/R/variogramST.R

Lines 255 to 256 in 8335d8e

gamma[j,i] <- 0.5*mean((data[,,colnames(m)[1]]@data[indSp[,1],1] - data[,,colnames(m)[1]]@data[indSp[,1]+indSp[,2],1])^2,
na.rm=TRUE)

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.

edzer added a commit that referenced this pull request Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants