I want to accomplish the following task without having to enter a for loop, but rather in a single apply() command.
I have a list a that I want to repeat N times, where N is the length of vector b, pasting each repetition of a to an element of b.
So far I have done the following MWE:
var <- paste("var", 1:4, sep="")
treat <- c("A","B")
spec <- paste("sp", 1:3, sep="")
a <- combn(var, 2, simplify = FALSE)#this 6 times, for each treatment and species
b <- do.call(paste, c(expand.grid(treat, spec), sep='.'))
a1 <- lapply(a, paste, b[1], sep='.')
a2 <- lapply(a, paste, b[2], sep='.')
a3 <- lapply(a, paste, b[3], sep='.')
a4 <- lapply(a, paste, b[4], sep='.')
a5 <- lapply(a, paste, b[5], sep='.')
a6 <- lapply(a, paste, b[6], sep='.')
a.final <- c(a1,a2,a3,a4,a5,a6)
a.final
It would be optimal if I could paste b before a.
Note my starting points are 3 vectors: var, treat and spec, so feel free to change anything from that point.