How to pass arguments as a list from function r

I have functions that contain many arguments. Therefore, I would like to create a list of arguments and pass them to a function.

For example, take the ?meanfunction:

mean(x, trim = 0, na.rm = FALSE, ...)

So, let's say I want to calculate the average value of 1:10, which is x here, but pass the other arguments as a list:

 gm <- list (trim = 0, na.rm = FALSE)

mean(1:10, gm)
Error in mean.default(1:10, gm) : 'trim' must be numeric of length one

I tried using do.call, but not working.

 do.call(mean,list(1:10, gm))
Error in mean.default(1:10, list(trim = 0, na.rm = FALSE)) : 
  'trim' must be numeric of length one
+4
source share

All Articles