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

spatSample returns insufficient values when na.rm=FALSE #1396

Closed
AMBarbosa opened this issue Jan 10, 2024 · 1 comment
Closed

spatSample returns insufficient values when na.rm=FALSE #1396

AMBarbosa opened this issue Jan 10, 2024 · 1 comment

Comments

@AMBarbosa
Copy link
Contributor

When na.rm=FALSE (the default), spatSample often returns a smaller sample than requested, even if there are more than enough pixels in the raster. This doesn't seem to happen when na.rm=TRUE:

r <- rast(system.file("ex/elev.tif", package="terra"))
r <- aggregate(r, 5)

ncell((r))  # 342
sum(!is.na(values(r)))  # 152

set.seed(1)
spatSample(r, 150)  # Warning message: [spatSample] fewer values returned than requested
spatSample(r, 150, na.rm = TRUE)  # OK
@rhijmans
Copy link
Member

Thanks, this seems to work better now.

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

No branches or pull requests

2 participants