As mentioned in the title, a lot of my data seems to be haven_labelled which means that any command I've been using on it in R keeps getting rejected in a way. I don't really know what to do.
Is there a way to convert them to something useable in R?
I can't seem to find a specific command that works online. I've been trying to figure out how to use lapply, etc but it doesn't seem to be working.
I saw this command online which is:
data2 <- data %>%
mutate(across(all_of(col_names), as.factor))
which apparently would convert the entire thing to an r factor but it just returned this error:
Error in `mutate()`:
ℹ In argument: `across(all_of(col_names), as.factor)`.
Caused by error in `across()`:
! Problem while evaluating `all_of(col_names)`.
Caused by error in `as_indices_impl()`:
! object 'col_names' not found
I also tried specifying a col_name but it returned something similar as well.
Table() command won't work due to this though, attributes() does return observations:
attributes(data$sgnptit)
$label
[1] "Signed petition last 12 months"
$format.stata
[1] "%1.0f"
$class
[1] "haven_labelled" "vctrs_vctr" "double"
$labels
Yes No
1 2