I'm sure this is simple, but I cannot find a solution ... I would like to use a variable containing a character string as argument for a function.
x <- c(1:10) myoptions <- "trim=0, na.rm=FALSE"
Now, something like
foo <- mean(x, myoptions)
should be the same as
foo <- mean(x, trim=0, na.rm=FALSE)
Thanks in advance!
You can use eval
and parse
:
foo <- eval(parse(text = paste("mean(x,", myoptions, ")")))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With