I'm working with a dataframe and two character vectors. I would like to replace all the elements of a column, given the assignment "rule" given by the character vectors. For example:
dat <- cbind(c("Zone 1A", "Zone 1C","Zone 2B ","Zone 2C"), 1:4)
#assignment rules
vec1 <- c("Zone 1A","Zone 1B ","Zone 1C","Zone 2A","Zone 2B","Zone 2C")
vec2 <- c("Zone 1","Zone 1","Zone 1","Zone 2","Zone 2","Zone 2")
This means that everytime I see an element of vec1 I replace it with the element of vec2 of the same index. So everytime I get "Zone 1B" y replace it with "Zone 1". I would like do have dat with its first column replaced using the assignment rule.
Note that vec1 and vec2 have the same length and dat randomly take values found in vec1.