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?