-
Notifications
You must be signed in to change notification settings - Fork 89
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
terra and raster extract output differs for categorical values #776
Comments
What would be a good use-case where you would want the "code" (integer level) rather than the actual "value" (factor label)? |
The "code" can be a key in a larger database where the "code" is used as the link in a relational data model. i.e. extracting the "values" and trying to join them to another table would break the model. |
Example data
Default
Solution 1: Set the active category to 0
Solution 2: Remove the levels
I could also add an argument "raw=TRUE" to Your idea of having the "raw values" as the R factor indices as well is good, in principle, but I am not sure if that is possible. I think they have to be from 1 to n. That would require adding, perhaps very many, empty levels if the raw values start at, say, 10,000. |
I have added argument
|
Thanks! |
Yes, I thought this might be case with using factor. That would add too much overhead for large values. A formal datatype that behaves as integer coded strings allowing non-consecutive integer levels doesn't exist currently in R. This would be useful in a variety of applications in R. |
For the raster package:
Returns the integer values of the categorical values in the dataset.
Returns a factor values but the levels are not the same integer levels within the raster dataset.
Per https://stackoverflow.com/questions/69533813/terra-extracting-incorrect-value-from-categorical-raster, this can be resolved by:
I could not find this anywhere in the documentation. Can an argument be added that turns off the "factoring" the values? Or can the returned factor include the correct integer values?
The text was updated successfully, but these errors were encountered: