Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

lapply

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

So to get :

peakabif(x1,npeaks=10)
peakabif(x2,npeaks=11)
peakabif(x3,npeaks=13)
peakabif(x4,npeaks=10)

Is this possible or do I need to reconsider using lapply ? Is a for loop inside the function would work ?

like image 705
Chargaff Avatar asked Dec 15 '22 15:12

Chargaff


1 Answers

You want to use mapply for this: mapply(peakabif, x=foo, npeaks=values)

like image 115
Matthew Plourde Avatar answered Feb 22 '23 23:02

Matthew Plourde