I need lapply to pass (to a function) values stored in a vector, successively.
values <- c(10,11,13,10)
lapply(foo,function(x) peakabif(x,npeaks=values))
Sometimes you can convert an existing function so that it will accept vectors (or lists) using Vectorize
vrep <- Vectorize(rep.int)
> vrep(list(1:4, 1:5), list(2,3) )
[[1]]
[1] 1 2 3 4 1 2 3 4
[[2]]
[1] 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
(Under the hood it's really a convenience wrapper for mapply
in the same way the read.table
is a wrapper for scan
.)