0

Here is my sample code:

library(haven) community_surveys <- read_sav("community_surveys.sav")

diss_data <- as.data.frame(community_surveys)

diss_data$FOC_1 <- as.factor(diss_data$FOC_1)
diss_data$DR_1 <- as.factor(diss_data$DR_1)
diss_data$IR_1 <- as.factor(diss_data$IR_1)
diss_data$HAITI <- as.factor(diss_data$HAITI)
diss_data$TREATMENT <- as.factor(diss_data$TREATMENT)

library(mice)

mice(diss_data, maxit = 10, m = 10)

I get this error below:

Error: `t.haven_labelled()` not supported

As far as the level of comprehension, I am a newbie R user with a couple intro classes and some reading under my belt. Any assistance much appreciated.

1 Answers1

2

Labelled data from haven leads to all sorts of weird problems. You could try one of the following:

If your data should be numeric: sapply(diss_data, haven::zap_labels)

For factors: sapply(diss_data, haven::as_factor)

You could also just try to replace the command in your code like this:

diss_data$FOC_1 <- haven::as_factor(diss_data$FOC_1)
diss_data$DR_1 <- haven::as_factor(diss_data$DR_1)
diss_data$IR_1 <- haven::as_factor(diss_data$IR_1)
diss_data$HAITI <- haven::as_factor(diss_data$HAITI)
diss_data$TREATMENT <- haven::as_factor(diss_data$TREATMENT)
Tim Ka
  • 92
  • 1
  • 8
  • I was able to solve before reading your post in a round about way. I went back to the original data set in SPSS and removed the value labels in the data. Then I saved and reloaded the data set into R. Once the value labels were removed the error disappeared. It would appear your answer is far more user friendly than reloading the data. Thank you for your assistance! – Rgrasshopper Jul 04 '20 at 16:11