Search code examples
rlapply

How to use different parameters based on a vector for each iteration of lapply?


I have a list of vectors for which I am lapplying the function lines to plot the content of each of the elements in the list. Example code following:

l <- list()
for(i in 1:10){l[[i]] <- rnorm(10)}
plot(l[[1]], t='n')
lapply(l, lines)

Is there a way of telling lapply that for each element use a different parameter, for instance, color or line type, so I can easily attribute the corresponding features I want to each element of the list? For instance, I'd like to have a vector of colors that match a particular element on the list.


Solution

  • I found that mapply is the way to go