2

My aim is to recode my variable into another variable with an inverted value:

f1_1_recAktuell <- recode(Dat_MonatAktuell$f1_1, "1=10; 2=9; 3=8; 4=7; 5=6; 6=5; 7=4; 8=3; 9=2; 10=1") 

This code has served me know for more than a year, yet out of a sudden I get this error message:

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

I guess there's something wrong with the data, yet I cannot find out what. The class of the variable is integer, it has no missing values.

Does anyone know what I can do?

Thanks in advance!

Hack-R
  • 22,422
  • 14
  • 75
  • 131
Rieke
  • 99
  • 5
  • Please provide a reproducible example (you can use `dput` to share the data). – Hack-R Jan 03 '17 at 15:20
  • You can just do `11-Dat_MonatAktuell$f1_1` if it is just values 1:10 in the vector. Please check if you are using `dplyr` as there is a `recode` in `dplyr` which can mask the one in `car`. In that case, do `car::recode(Dat_MonatAktuell$f1_1, "1=10; 2=9; 3=8; 4=7; 5=6; 6=5; 7=4; 8=3; 9=2; 10=1")` – akrun Jan 03 '17 at 15:21

1 Answers1

2

The warning message is due to use of recode from dplyr (possibly the OP loaded the package?) instead of from car. This happens when dplyr::recode masks the same function in car. We can specify the package name before the function as a remedy i.e. car::recode

v1 <- 1:10
car::recode(v1, "1=10; 2=9; 3=8; 4=7; 5=6; 6=5; 7=4; 8=3; 9=2; 10=1") 
#[1] 10  9  8  7  6  5  4  3  2  1

Also, we can use

11-v1 
#[1] 10  9  8  7  6  5  4  3  2  1

The warning can be reproduced with dplyr::recode

 dplyr::recode(v1, "1=10; 2=9; 3=8; 4=7; 5=6; 6=5; 7=4; 8=3; 9=2; 10=1") 
 #[1] "1=10; 2=9; 3=8; 4=7; 5=6; 6=5; 7=4; 8=3; 9=2; 10=1" NA                                                  
 #[3] NA                                                   NA                                                  
 #[5] NA                                                   NA                                                  
 #[7] NA                                                   NA                                                  
 #[9] NA                                                   NA                                                  
Warning message:
 Unreplaced values treated as NA as .x is not compatible.
  Please specify replacements exhaustively or supply .default

To get the expected output, we can also use dplyr::recode in this way

dplyr::recode(v1, `1` = 10, `2` = 9, `3` = 8, `4` = 7, 
                 `5` = 6, `6` = 5, `7`=4, `8` = 3, `9` = 2, `10` = 1)
#[1] 10  9  8  7  6  5  4  3  2  1
akrun
  • 874,273
  • 37
  • 540
  • 662