Can lapply pass (to a function) values stored in a vector, successively

后端 未结 3 1269
误落风尘
误落风尘 2021-01-19 18:24

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))
         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-19 19:00

    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...)

提交回复
热议问题