vendredi 18 décembre 2020

Conditionally change values of data.frame but keep everything else unchanged in R

Below, I'm wondering how to only change values of my data according to the following condition:

if ir== 2, "ESL", if ir == 3, "EFL", if ir == 1, "timed", if ir == 0, "untimed"

But I wonder how to keep everything else unchanged?

(ir <- data.frame(item=1:10,study.name = paste("Study", c(1,1,2,3,3,3,4,4,5,5)),
                 group.name = c(1,2,1,1,2,3,1,2,1,2),  
                 Time = c(1, 0, 1, 0, 1, 0, 1, 0, 0, 1), 
                   Time.1 = c(1, 0, 1, 0, 1, 0, 1, 1, 1, 0),
                   Setting = c(2, 2, rep(3, 8)),
                   Setting.1 = c(2, 2, 3, 2, 2, 2, 3, 3, 3, 3)))

# I have tried the following without success:

(ir1 <- data.frame(ifelse(ir== 2, "ESL", ifelse(ir == 3, "EFL", ifelse(ir == 1, "timed", "untimed")))))
 

Aucun commentaire:

Enregistrer un commentaire