I have the following data-frame:
xis <- data.frame(x1=c("**alo.123", "**alo.132", "**alo.199"), x2=c("sp", "mg", "rj"), x3=c(NA))
I would like to create a new column using gsub as follows:
x3[1] <- gsub("alo", xis$x2[1], xis$x1[1])
x3[2] <- gsub("alo", xis$x2[2], xis$x1[2])
x3[3] <- gsub("alo", xis$x2[3], xis$x1[3])
I would not like to use the for and I know there is a possibility to use maply for this, such as:
xis$x3 <- mapply(gsub,"alo", xis$x2, xis$x1)
Would there be a way to use% dplyr% for this? Something like:
xis <- mutate(xis, x3 = gsub("alo", x2, x1)