I am encountering a problem when I run the following code to try to convert several columns of data from character to factor:
library(readxl)
library(dplyr)
"LR_df1"<-read_excel("Correct file location.xlsx",sheet="Correct sheet")
LR_df1 %>%
as_tibble()%>%
mutate(across(c(SiteCode, S01UsualResidence), as.factor))
The initial output looks good, and it appears that the specified columns have been converted:
# A tibble: 1,075 x 238
A CaseId SiteCode S01Gender S01UsualResidence
<dbl> <dbl> <fct> <chr> <fct>
But then when I run:
summary(LR_df1$SiteCode)
I get:
> summary(LR_df1$SiteCode) Length Class Mode 1075 character character
So it appears that the variable hasn't been converted. I'd be very grateful to anyone who can show me what I'm doing wrong.