This almost got me there, but I'm still having some trouble. Working with my data set and using the vignette, I was able to write a line that half works:
pubdata=pubdata %>% mutate(across(.cols = "Race", "Sex", .fns = factor))
This transforms the Race variable into a factor, but for some reason it doesn't do anything with the Sex variable. It also completely destroys the Race variable somehow:
'data.frame': 1225 obs. of 2 variables:
Race: Factor w/ 1 level "Sex": NA NA NA NA NA NA NA NA NA NA ...
Sex : int 2 2 2 1 2 1 1 1 2 2 ...
Going back to the vignette, I tried to tweak what they had near the bottom (in the "how to transform existing code") to this:
pubdata %>% mutate(across(c(pubdata, "Race","Sex")), factor)
But this doesn't work at all, and just returns an error:
Error: Problem with mutate() input ..1.
x Must subset columns with a valid subscript vector.
x Subscript has the wrong type `data.frame<
Race: factor<9f711>
Sex : integer
. i It must be numeric or character. i Input ..1isacross(c(pubdata, "Race", "Sex")). Run rlang::last_error()` to see where the error occurred
For reference, this is what the old code does, and is exactly what I'm trying to duplicate:
pubdata=pubdata %>% mutate_at(vars("Race", "Sex"),factor)
str(pubdata)
'data.frame': 1225 obs. of 2 variables:
Race: Factor w/ 4 levels "1","2","3","4": 2 2 1 1 1 1 1 1 1 1 ...
Sex : Factor w/ 2 levels "1","2": 2 2 2 1 2 1 1 1 2 2 ...