I have these two lines of R codes:
df$symbol <- gsub("\\^", "-P", df$symbol) # find "^" and change it to "-P"
df$symbol <- gsub("/", "-", df$symbol) # find "/" and change it to "-"
How can I combine them into one line?
Thank you!
I have these two lines of R codes:
df$symbol <- gsub("\\^", "-P", df$symbol) # find "^" and change it to "-P"
df$symbol <- gsub("/", "-", df$symbol) # find "/" and change it to "-"
How can I combine them into one line?
Thank you!
Given that you have two different replacement strings, there may not be a way to do this with just a single call to gsub
. However, you could chain two calls to gsub
here:
df$symbol <- gsub("/", "-", gsub("\\^", "-P", df$symbol))