Let's assume I have a dataset like this one:
df1 = data.frame(Name=c("<HELLO>_World","World","HELLO_<WORLD>"),
Generic=c("<HELLO>","<HELLO>","<WORLD>"),
Substitution = c("hello1","world","world1"),
Flag = c("Yes","No","Yes"))
Now, based on the flag, I'd like to obtain the replacement in the "Name" column of the string in the substitution one, In the end the dataframe should look like this:
final <- data.frame(Name=c("hello1_World","world","HELLO_world1"))
I've tried with something like this:
index <- df1$Flag == "Yes"
df1$Name[index] <- gsub(df1$Generic[index],df1$Substitution[index])
Maybe it should be done in a new column (also acceptable)