I'm trying to get comfortable with using the Tidyverse, but data type conversions are proving to be a barrier. I understand that automatically converting strings to factors is not ideal, but sometimes I would like to use factors, so some approach to easily converting desired character columns in a tibble to factors would be excellent. I prefer to read in excel files with the readxl package, but factors aren't a permitted column type! I can go through column by column after the fact, but that's really not efficient. I want either of these two following things to work:
Read in a file and simultaneously specify which columns should be read as factors:
data <- read_excel(path = "myfile.xlsx", col_types=c(col2="factor", col5="factor)))
Or this function would be excellent for many reasons, but I can't figure out how it's supposed to work. The col_types function is very confusing to me:
diamonds <- col_types(diamonds, cols=c(cut="factor", color="factor", clarity="factor"))
Thanks in advance!