4
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 the possibility to use the maply for this, as, for example:
xis$x3 <- mapply(gsub,"alo", xis$x2, xis$x1)
There would be a way to use the mutate
dplyr for that? Something like:
xis <- mutate(xis, x3 = gsub("alo", x2, x1)