# R: Revalue multiple special characters in a data.frame

R noob here..

I have the following data frame

>data
Value Multiplier
1  15    H
2   0    h
3   2    +
4   2    ?
5   2    k


where the multiplier is of class factor. The values of K & k is 3, + is 5 and ? is 2.

I have used

> data$Multiplier <- revalue(data$Multiplier, c("+"="5"))
> data$Multiplier <- revalue(data$Multiplier, c("?"="2"))
> data$Multiplier <- revalue(data$Multiplier, c("K"="3"))
> data$Multiplier <- revalue(data$Multiplier, c("k"="3"))


Is there a better way of doing it?

> newValueVector <- c("+"="5", "?"="2", "K"="3", "k"="3")
> data$Multiplier <- revalue(data$Multiplier, newValueVector)

• Thanks @amustafa. Now that i think about it, yes I should have been able to figure it out. I think I was caught of guard by the = sign in the string. – Drj Oct 17 '15 at 22:26