I have a data set where every observation has an ID value describing multiple things, for example AE1 indicates site A, type E, observation 1. I am trying to generate a column just for type so in the above example I am trying to filter out the E while removing the other data.
I have looked into using gsub
however each new type pattern seems to overwrite the previous. The approach that appears to get me the closest is using gsubfn
as shown below:
library(gsubfn)
x <- c("AE1", "AE2", "AD1", "AD2", "BE1", "BE2", "BD1", "BD2")
y <- gsubfn(".", list("E" = "easy", "D" = "difficult"), x)
y
[1] "Aeasy1" "Aeasy2" "Adifficult1" "Adifficult2" "Beasy1" "Beasy2" "Bdifficult1" "Bdifficult2"
The issue with the result is that I still need to remove the initial letter and the final number. In reality I have four type categories not just "E" and "D"
Thanks in advance.