Skip to content

Instantly share code, notes, and snippets.

@Nowosad
Created November 27, 2018 15:17
Show Gist options
  • Save Nowosad/34bdbcafb4a58daecf30992970a1266a to your computer and use it in GitHub Desktop.
Save Nowosad/34bdbcafb4a58daecf30992970a1266a to your computer and use it in GitHub Desktop.
How to change the class of variables within an sf object?
library(sf)
library(dplyr)
library(spData)
str(nz)
# change class for one column
nz2 = nz %>%
mutate(Land_area = as.factor(Land_area))
str(nz2)
# change class for more than one column
nz3 = nz %>%
mutate_if(is.character, as.factor)
str(nz3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment