I have the following dataframe:
set.seed(1)
df <- data.frame(X1 = sample(c(letters[1:5],NA),10,replace=TRUE),
X2 = sample(c(letters[1:5],NA),10,replace=TRUE),
X3 = sample(c(letters[1:5],NA),10,replace=TRUE),
stringsAsFactors = FALSE)
X1 X2 X3
1 b b <NA>
2 c b b
3 d e d
4 <NA> c a
5 b e b
6 <NA> c c
7 <NA> e a
8 d <NA> c
9 d c <NA>
10 a e c
I want to replace a
for 5, b
for 4, c
for 3, d
for 2, and e
for 1, with:
df %>% lapply(., plyr::mapvalues(, c("a","b","c","d","e"), c(5,4,3,2,1)))
But it doesn't work: I get a warning that it's missing the first argument of the function mapvalues()
.
Does anyone know what I am doing wrong?