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(
dat[2:3] <- lapply(dat[2:3], gsub, pattern = '[a]{2,}', replacement = '')
The result:
> dat attr type1 type2 1 1 2 2 b 3 3 4 4 b
Data used:
dat <- data.frame(attr = c(1:4), type1 = c('aa','b'), type2 = c("aaa", "aa"))