I am trying to use if-else to recode a column based on two conditions. Here is an example of data.
score.1 <- c(1,2,3,4,5,6,7,8,9,10)
cat <- c("a","b","c","d","e","a","b","c","d","e")
data <- data.frame("score.1"=score.1,"cat"=cat)
cut.score.1 <- 2.5
cut.score.2 <- 7.5
data[,1] <- ifelse(data[,1] < cut.score.1, data[,1] == cut.score.1, data[,1])
data[,1] <- ifelse(data[,1] > cut.score.2, data[,1] == cut.score.2, data[,1])
> data[,1]
[1] 0 0 3 4 5 6 7 0 0 0
However, when the condition/s meet, Os are printed. Any thoughts on that?
Thanks
Aucun commentaire:
Enregistrer un commentaire