I've got a function, e.g. fun(a, b = 1, c = 3, ...)
, that takes a number of arguments, some of which have default values. I would like to call this function using lapply(X, FUN, ...)
, but specify explicitly which argument I would like X
to supply. In the example above, the X
vector could be supplied for a
or b
or c
, or xyz
in the ...
.
Normally I might call lapply(1:5, fun, a = 4)
and I imagine it would use 1:5
as the b
argument.
- Is there a way to make that more explicit?
- What if I want to use the default argument for
b
and use1:5
forc
? - What if I want to use
1:5
as anxyz
argument in the...
?
lapply(1:5,function(x,a=4,..,) { } )
– Ericklapply
itself will only give you a single entry from the list on which it is operating. – Ribband