See the following reproducible example:
require(tidyverse)
set.seed(1)
reprex_df <- data.frame(
var1 = sample(1:10),
var2 = sample(11:20),
var3 = sample(21:30)
)
I am trying to create a new column containing URLs created from concatenating the other variables from each row into a string with "https://www.google.com/search?q=", using the following code:
reprex_df %>% mutate(new_col = c(paste("https://www.google.com/search?q=", var1, var2, var3, sep="+")))
Which results in:
https://www.google.com/search?q=+3+13+30
The problem with this is that it puts a +
between the https://www.google.com/search?q=
and var1
, which is not a valid format for the URL. I need no separator between these strings. Like so:
https://www.google.com/search?q=3+13+30
Can I somehow specify to use a different separator for this part of the conjunction using paste()
, or do I have to take a totally different approach? Any ideas?