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
as.data.frame defaults to na.rm = T for spatraster with many layers #792
Comments
With trepidation I changed the default to
That could also be sensible default, as it would not change the behavior for a single layer SpatRaster |
What is the status of this issue? In 57ab669 you changed |
Or if missing values are to be removed by default, perhaps there should be message that some observations have been removed from the data frame? |
I will check how many revdeps break with that (but of course there is other code that will break that is not in dependent packages). But whether they do or not, why you would you want records with only NAs. I suppose that would only be on the rare case that you would want to manipulate the data.frame and then recreate a SpatRaster from that. Is that necessary? |
To better express myself: I would hope and think that going from a SpatRaster to a data.frame and back would be rare. Also, it would be easy to detect the problem when creating the new SpatRaster as the number of rows in the data.frame won't match ncell of the SpatRaster. |
Yes, exactly. I have some workflows where I convert the raster to data frame and then use kmeans clustering or convert to Here is example: library("terra")
r = rast(system.file("ex/elev.tif", package = "terra"))
df = as.data.frame(r, na.rm = FALSE)
mdl = kmeans(na.omit(df), centers = 3)
output = rep(NA, ncell(r))
output[complete.cases(df)] = mdl$cluster
clustering = rast(r, vals = output)
### if `as.data.frame(r, na.rm = NA)` there is warning
### but I didn't know why after updating terra this code stopped working
# Warning message:
# In output[complete.cases(data)] = mdl$cluster :
# number of items to replace is not a multiple of replacement length |
The predict function of the terra package cannot be combined with models trained with XGBoost. The raster data is extensive, and cannot be converted to a data frame, which is causing me a great deal of distress. |
@Hongwuliang: I think it can. See: https://stackoverflow.com/a/74330713/635245 Please create a minimal, self-contained, reproducible example and use that for a question on stackoverflow.com. This github site is not for answering this type of "how do I do this?" questions. |
The argument
na.rm
now defaults to TRUE in theas.data.frame
function.While this makes sense for single layer rasters its really unhelpful for multi-band rasters.
This is also a change from the previous raster package, where the default for
na.rm
was FALSEThe text was updated successfully, but these errors were encountered: