"Error: Can't convert <haven_labelled> to character"

10.8k views Asked by At

My student and I both loaded the same dataset, installed the same packages, and were running the same code. When I run "frq" I get a frequency table and the variable is labeled as "numeric." When my student runs the same code, she gets "Error: Can't convert <haven_labelled> to character."

Any thoughts on where we might be going wrong?

4

There are 4 answers

0
Gegh On

I got same problem. I used library(tidyverse) and it helps.

1
Rael On

I had a similar problem, similar in the sense that when I tried to coerce a varriable to 'character', I got a similar error report. I used library(haven) and it worked for me.

0
pbraeutigm On

Load the library haven and it should work. It's working fine for me in 2023.

install.packages(haven)
library(haven)
0
psyguy On

I could say it with more certainty if you had provided an Minimal, Reproducible Example (MWE).

However, borrowing from this answer, the error that you get is most probably because the variable in question is of the type haven_labelled, which not all R functions can deal with.

You should, in principle, be able to solve the issue by changing the variable type to R-friendly factor using haven::as_factor.