mardi 11 décembre 2018

R - How do I combine mutate_all and ifelse

I would like to iterate over all columns of a data.frame with mutate_all() and then selectively change values using ifelse().

testdf <- data.frame("a"=c(1,2,3), "b"=c(4,5,6), "c"=c(7,8,9))

mutate_all(testdf, ifelse(.>9,10,.))

But this does not work. I always get "object '.' not found". How do I refer to the individual values passed through the mutate_all() function? I thought the '.' worked that way? This works:

mutate_all(testdf, funs(.*2))

Aucun commentaire:

Enregistrer un commentaire