You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
levels(lines_HARV$TYPE) should return the unique values within TYPE column containing categorical variables. However, in the exercise this actually returns NULL.
I did a little investigation and for this to work, when reading the spatial data you need to include "stringsAsFactors = T" parameter in str_read.
In lesson: Introduction to Geospatial Raster and Vector Data with R
Episode7: Explore and Plot by Vector Layer Attributes
https://datacarpentry.org/r-raster-vector-geospatial/07-vector-shapefile-attributes-in-r/index.html
levels(lines_HARV$TYPE) should return the unique values within TYPE column containing categorical variables. However, in the exercise this actually returns NULL.
I did a little investigation and for this to work, when reading the spatial data you need to include "stringsAsFactors = T" parameter in str_read.
lines_HARV <- st_read("data/NEON-DS-Site-Layout-Files/HARV/HARV_roads.shp", stringsAsFactors = T)
Or even better, if st_read is not flagged with stringAsFactors =T, use...
levels(as.factor(lines_HARV$TYPE))
The reason for this is due to a change of R code in the way it handles string values & factors. A good explanation for this can be found at:
https://simplystatistics.org/posts/2015-07-24-stringsasfactors-an-unauthorized-biography/
The text was updated successfully, but these errors were encountered: