I am trying to replace occurances of string in data.frame of strings by another strings from another data.frame of strings.
Multiple base strings where substrings should be replaced
# base strings which I want to replace
base <- data.frame(cmd = rep("this is my example <repl1> and here second <repl2> ...", nrow(repl1)))
Replacement strings
# definition of replacement strings
repl1 <- data.frame(as.character(1:10))
repl2 <- data.frame(as.character(10:1))
I tried to iterate over the data.frame with lapply...
# what I have tried
lapply(base, function(x) {gsub("<repl1>", repl1, x)})
As result I have than following ...
[1] "this is my example c(1, 3, 4, 5, 6, 7, 8, 9, 10, 2) and here second <repl2> ..."
[2] "this is my example c(1, 3, 4, 5, 6, 7, 8, 9, 10, 2) and here second <repl2> ..."
[3] "this is my example c(1, 3, 4, 5, 6, 7, 8, 9, 10, 2) and here second <repl2> ..."
but I would like to achieve ...
[1] "this is my example 1 and here second 10 ..."
[2] "this is my example 2 and here second 9 ..."
[3] "this is my example 3 and here second 8 ..."
Thx for each suggestion :)