Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206209

passing several arguments to FUN of lapply (and others *apply)

$
0
0

I have a question regarding passing multiple arguments to a function, when using lapply in R.

When I use lapply with the syntax of lapply(input, myfun); - this is easily understandable, and I can define myfun like that:

myfun <- function(x) {
 # doing something here with x
}

lapply(input, myfun);

and elements of input are passed as x argument to myfun.

But what if I need to pass some more arguments to myfunc? For example, it is defined like that:

myfun <- function(x, arg1) {
 # doing something here with x and arg1
}

How can I use this function with passing both input elements (as x argument) and some other argument?


Viewing all articles
Browse latest Browse all 206209

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>