Hi. I'm working on a school project and i have this 5 point likert instrument which i have to change some variables because some variables represent "negative variables".
What i have to do is: if the questions's answer is 1, i gotta change it to 5, if its 2, i gotta change it to 4 and if its 3 it stays 3.
I have a big dataframe with all the data we collected, called merged_B. This is what i tried so far:
I made a vector with all the questions that i have to replace the values
negativas <- c(merged_B$`(adp18)`,merged_B$`(adp20)`,merged_B$`(adp22)`,merged_B$`(adp24)`, merged_B$`(adp26)`,merged_B$`(adp18)`,merged_B$`(aaa18)`,merged_B$`(aaa26)`,merged_B$`(aaa24)`,merged_B$`(aaa22)`,merged_B$`(aaa20)`,merged_B$`(atc10)`,merged_B$`(atc2)`,merged_B$`(atc4)`,merged_B$`(atc6)`,merged_B$`(atc8)`,merged_B$`(atm4)`,merged_B$`(atm8)`,merged_B$`(atm6)`,merged_B$`(atm10)`,merged_B$`(atm2)`,merged_B$`(cli18)`,merged_B$`(cli10)`,merged_B$`(cli2)`,merged_B$`(cli6)`,merged_B$`(cli12)`,merged_B$`(cli8)`,merged_B$`(cpt10)`,merged_B$`(cpt2)`,merged_B$`(cpt4)`,merged_B$`(cpt6)`, merged_B$`(cpt8)`,merged_B$`(crp10)`,merged_B$`(crp12)`,merged_B$`(crp18)`,merged_B$`(crp20)`,merged_B$`(crp4)`,merged_B$`(crp6)`,merged_B$`(crp8)`,merged_B$`(ctd2)`,merged_B$`(ctd4)`,merged_B$`(ctd6)`,merged_B$`(ctd8)`,merged_B$`(cmd10)`,merged_B$`(cmd2)`,merged_B$`(cmd6)`,merged_B$`(cmd4)`,merged_B$`(cmd8)`,merged_B$`(cmn4)`,merged_B$`(cmn6)`,merged_B$`(cmn8)`,merged_B$`(cmn2)`,merged_B$`(coo28)`,merged_B$`(coo8)`,merged_B$`(coo20)`,merged_B$`(coo26)`,merged_B$`(coo22)`,merged_B$`(coo23)`, merged_B$`(coo16)`,merged_B$`(flx10)`,merged_B$`(flx4)`,merged_B$`(ldc6)`,merged_B$`(ldc8)`,merged_B$`(ldc10)`,merged_B$`(ldc4)`,merged_B$`(ldc2)`,merged_B$`(mdc15)`,merged_B$`(mdc12)`,merged_B$`(mdc14)`,merged_B$`(mdc6)`,merged_B$`(mdc2)`,merged_B$`(mdc10)`,merged_B$`(mot10)`,merged_B$`(mot4)`,merged_B$`(mot2)`,merged_B$`(mot6)`,merged_B$`(mot8)`,merged_B$`(plc10)`,merged_B$`(plc2)`,merged_B$`(plc4)`,merged_B$`(plc6)`,merged_B$`(plc8)`,merged_B$`(rec8)`,merged_B$`(rec2)`,merged_B$`(rec12)`,merged_B$`(rec4)`,merged_B$`(rec14)`,merged_B$`(rec17)`,merged_B$`(rec10)`,merged_B$`(tol6)`,merged_B$`(tol4)`,merged_B$`(tol17)`,merged_B$`(tol10)`,merged_B$`(tol2)`,merged_B$`(tol8)`)
And then i tried to replace the variables like i said by doing
merged_B_negativas <- for (i in negativas){
merged_B[i== "1) Não tem nada a ver comigo"] <- "5"
merged_B[i== "2) Tem pouco a ver comigo"] <- "4"
merged_B[i== "3) As vezes tem e as vezes não tem a ver comigo"] <- "3"
merged_B[i== "4) Tem muito a ver comigo"] <- "2"
merged_B[i== "5) Tem tudo a ver comigo"] <- "1"
}
I could do it 1 by 1 but there are almost 100 questions, that would be a bummer.
I suffer a bit with loops so all help would be appreciated