I have a vector where I want to replace one element with several elements, I can replace it with one, but not multi-level, can anyone help?
For example, I have
data <- c('a', 'x', 'd') > data [1] "a" "x" "d"
I want to replace "x" with "b", "c" to get
[1] "a" "b" "c" "d"
but
gsub('x', c('b', 'c'), data)
gives me
[1] "a" "b" "d" Warning message: In gsub("x", c("b", "c"), data) : argument 'replacement' has length > 1 and only the first element will be used
replace r gsub
user1165199
source share