I want to replace the strings \"aa\" and \"aaa\" in the dataframe below with\"\"
\"aa\"
\"aaa\"
\"\"
data = data.frame(attr = c(1:4), type1=c(
You could just set option fixed = FALSE and delete all the a's.
fixed = FALSE
data <- as.data.frame(apply(data, 2, function(x) gsub("a",'', x, fixed = FALSE))) data # attr type1 type2 # 1 1 # 2 2 b # 3 3 # 4 4 b