1

I am trying to recode some survey responses. The responses are text and I want to recode them in to numbers. However, some strings don't get recoded. I can't seem to find the reason why that specific string ("plutôt insatisfait" doesn't get recoded to "3") is an issue.

View(VPFR_Q_raw)
table(VPFR_Q_raw$Q1)

   insatisfait             neutre   plutôt satisfait plutôt insatisfait          satisfait   très insatisfait 
            82                 96                229                 87                527                199 
très satisfait 
           528 

unique(VPFR_Q_raw$Q1)
[1] "insatisfait"        "satisfait"          "très insatisfait"   "très satisfait"     "plutôt satisfait"  
[6] "neutre"             "plutôt insatisfait"

VPFR_Q_raw$Q1[VPFR_Q_raw$Q1 == "très insatisfait"] <- 1
VPFR_Q_raw$Q1[VPFR_Q_raw$Q1 == "insatisfait"] <- 2
VPFR_Q_raw$Q1[VPFR_Q_raw$Q1 == "plutôt insatisfait"] <- 3
VPFR_Q_raw$Q1[VPFR_Q_raw$Q1 == "neutre"] <- 4
VPFR_Q_raw$Q1[VPFR_Q_raw$Q1 == "plutôt satisfait"] <- 5
VPFR_Q_raw$Q1[VPFR_Q_raw$Q1 == "satisfait"] <- 6
VPFR_Q_raw$Q1[VPFR_Q_raw$Q1 == "très satisfait"] <- 7

table(VPFR_Q_raw$Q1)

             1                  2                  4                  5                  6                  7 
           199                 82                 96                229                527                528 
plutôt insatisfait 
                87 

Another example where there are no strange signs: It works perfectly with Q1, but it doesn't work with Q2 while I'm using the same syntax.

#Q1
unique(VPNL_Q_raw$Q1)

"tevreden" "eerder tevreden" "heel tevreden" "heel ontevreden" "neutraal" "ontevreden" "eerder ontevreden"

VPNL_Q_raw$QR1 <- recode(VPNL_Q_raw$Q1,"
'heel ontevreden'=1;
'ontevreden'=2;
'eerder ontevreden'=3;
'neutraal' = 4;
'eerder tevreden'=5;
'tevreden'=6;
'heel tevreden'=7")
table(VPNL_Q_raw$Q1,VPNL_Q_raw$QR1)

result Q1

#Q2
unique(VPNL_Q_raw$Q2)

"zeker wel" "wel" "zeker niet" "neutraal" "eerder wel" "eerder niet" "niet"

VPNL_Q_raw$QR2 <- recode(VPNL_Q_raw$Q2,"
'zeker niet'= 1;
'niet'= 2;
'eerder niet'= 3;
'neutraal'= 4;
'eerder wel'= 5;
'wel'= 6;
'zeker wel'= 7")
table(VPNL_Q_raw$Q2,VPNL_Q_raw$QR2)

result Q2

Kimberley
  • 23
  • 4
  • 3
    there is probably a typo somewhere for your third value – Cath Jun 12 '17 at 13:54
  • 1
    apart from that, you may want to have a look at function `switch` – Cath Jun 12 '17 at 13:56
  • You could try `dplyr::recode` inside of a call to `dplyr::mutate`. The easier and cleaner syntax can help you to spot typos and other errors. Also, a reproducible example would help us help you :-) – RobertMyles Jun 12 '17 at 13:59
  • Maybe take a look at https://stackoverflow.com/questions/9511281/handling-special-characters-e-g-accents-in-r: R might be recognizing the `ô` incorrectly. – Matt Jun 12 '17 at 13:59
  • Thanks for your answers! I uploaded another example where there are no strange signs, I also used 'recode' – Kimberley Jun 13 '17 at 08:34

0 Answers0