enter code here
I have a SPSS data, loaded using haven package, which I need to change values 0-4 to 4-0 in several columns called here as "tss" in the data psychophobia (psychophobia$tss1, psychophobia$tss2...), creating a new column as recodtss... additionally, there are several NAs data.
I´ve tried this code:
old <- 0:4
new <- c(4:0)
psychophobia$Recodtss01 <- psychophobia$tss01[psychophobia$tss01 %in% old] <-new[match(psychophobia$tss01,old,nomatch = "NA")]
psychophobia$Recodtss02 <- psychophobia$tss01[psychophobia$tss02 %in% old] <-new[match(psychophobia$tss02,old,nomatch = "NA")]
The problem is that the current output is
psychophobia$tss01 1 4 1 1 NA NA 3 2 0 1
psychophobia$Recodtss01 1 4 1 1 NA 3 2 0 1 2
Can anyone help to understand why? :)