I have a vector of nth element and a list with the same number of elements, each is a vector. For a simple equivalent example:
v <- c("a","b")
num1 <- c(1,2,3)
num2 <- c(10,20,30)
numList <- list(num1,num2)
The output I want is:
"a1" "a2" "a3" "b10" "b20" "b30"
I can do this with a for loop:
output <- vector()
for (i in 1:length(v)) {
output <- c(output, paste0(v[i], numList[[i]]))
}
output
[1] "a1" "a2" "a3" "b10" "b20" "b30"
But is there an easier or more clever way, using lapply or tidyverse? I tried the following and did not get what I want:
lapply(numList, function(x) paste0(v, x))