I am trying to read a dataframe from an Excel file using the read_excel()
function from the Tidyverse
(ReadXl
) package in R. I would like to read a column as.factor
, however, the col_types
argument in the read_excel()
function does not seem to support as_factor
.
I now use the following workaround:
Sample code:
library(tidyverse)
library(readxl)
df <– read_excel("name_of_excel_file.xlsx")
df <- df %>%
mutate(column = as.factor(column))
Is there an easier (and more direct) way to do this?