0

I have a numeric variable (V110) that takes on values between 1-4. As the numbers stand for higher (1) and lower (4) trust in the govt, I want to recode them, so that the highest value signifies the highest and the lowest value the lowest trust. Now I tried the following syntax:

wv6$n.V110 <- recode(wv6$V110, "1=4; 2=3; 3=2; 4=1")

But R keeps outputting an error message saying:

Warning message: Unreplaced values treated as NA as .x is not compatible. Please specify replacements exhaustively or supply .default

I checked the individual answers i.e. values given and some of them say -2 (i.e. a value that doesn't belong to the section "1-4", could that be the problem? I tried to add both ".default=NA" or "else=NA" at the end of the syntax but this doesn't make the error go away. Any help?

Psidom
  • 209,562
  • 33
  • 339
  • 356
ureuss
  • 1
  • 1
  • 1
  • 1

1 Answers1

5

Might it be that you loaded the packages car and dplyr?

recode can be used by both package. That for you need to specify which package will apply when using recode.

In your case:

wv6$n.V110 <- car::recode(wv6$V110, "1=4; 2=3; 3=2; 4=1")

That worked out perfectly for me as car was masked by dplyr.

M--
  • 25,431
  • 8
  • 61
  • 93
Rieke
  • 99
  • 5