Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix variogramST.STIDF #135

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Fix variogramST.STIDF #135

wants to merge 5 commits into from

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.

R/zzz.R Outdated Show resolved Hide resolved
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