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))
There are a couple of ways to handle this. You could try a straight indexing vector approach.
lapply(1:length(foo), function(i) peakabif(foo[i], npeaks=values[i]))
(and someone already beat me to the mapply version...)