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

4

9

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?

Nifty answered 7/12, 2020 at 17:4 Comment(0)
R
9

Load the library haven and it should work. It's working fine for me in 2023. According to @Pål Bjartan haven is not part of the tidyverse package "and not loaded automatically with library(tidyverse)"

install.packages("haven")
library(haven)
Rimple answered 9/10, 2023 at 8:13 Comment(1)
This did the trick for me. I couldn't understand why I got the error, as I already had tidyverse loaded. As it turns out, haven is not part of the core packages of Tidyverse, and not loaded automatically with library(tidyverse).Jonas
S
6

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

Snuffle answered 10/12, 2020 at 7:15 Comment(0)
F
2

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.

Fourchette answered 19/4, 2023 at 16:18 Comment(0)
S
2

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.

Sidonia answered 7/9, 2023 at 16:21 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Diffractometer

© 2022 - 2025 — McMap. All rights reserved.