I have a row vector in the following format:
strings <- c("UUDBK", "KUVEB", "YVCYE")
I also have a data frame like this:
replacewith <- c(8, 4, 2) searchhere <- c("UUDBK, YVCYE, KUYVE, IHVYV, IYVEK", "KUVEB, UGEVB", "KUEBN, IHBEJ, KHUDN") dataframe <- data.frame(replacewith, searchhere)
I want the row vector to be replaced with the value in the corresponding "replacewith" column in this data frame. I am currently doing this:
final <- sapply(as.character(strings), function(x) as.numeric(dataframe[grep(x, dataframe$searchhere), 1]))
However, it is very difficult to calculate to do this with a character vector with a length of 10 ^ 9.
What is the best way to do this?
Thanks!
source share