In R, in a data frame, I want to take the code number of a tree species in one column and create a new column in the data frame with recoded text name of the species like below. I can create a matrix of tree name = code number, but how do I apply this to a long and mixed column of just numerical values?
> treeco <- c(4, 3, 4, 5, 3, 2, 2, 1, 4)
> spcode <- c("oak" = 1, "ash" = 2, "elm" = 3, "beech" = 4, "hazel" = 5)
> treesp <- data.frame(spcode)
> treesp
species
oak 1
ash 2
elm 3
beech 4
hazel 5
This is the solution I am looking for:
treeco spcode
1 4 beech
2 3 elm
3 4 beech
4 5 hazel
5 3 elm
6 2 ash
7 2 ash
8 1 oak
9 4 beech