0 votes
1 view
in R Programming by (7.3k points)

I have a function f(var1, var2) in R. Suppose we set var2 = 1 and now I want to apply the function f() to the list L. Basically I want to get a new list L* with the outputs


How do I do this with either apply, mapply or lapply?

1 Answer

0 votes
by (25.4k points)

To apply a function to multiple parameters, you can pass an extra variable while using any apply function.

Here are some examples:



myFun <-function(var1,var2)





[1] 10 40 90

mylist <- list(a=10,b=20,c=30)

myfun <- function(var1,var2){



var2 <- 5

sapply(mylist,myfun, var2=var)

  a   b   c 

 50 100 150 

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !