[R] How to write a function that accepts unlimited number of input arguments?
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Mar 9 22:59:25 CET 2009
Try this:
sum.test <- function(...) sum(c(...))
More commonly one uses the list(...) construct.
On Mon, Mar 9, 2009 at 11:32 AM, Sean Zhang <seanecon at gmail.com> wrote:
> Dear R-helpers:
> I am an R newbie and have a question related to writing functions that
> accept unlimited number of input arguments.
> (I tried to peek into functions such as paste and cbind, but failed, I
> cannot see their codes..)
>
> Can someone kindly show me through a summation example?
> Say, we have input scalar, 1 2 3 4 5
> then the ideal function, say sum.test, can do
> (1+2+3+4+5)==sum.test(1,2,3,4,5)
>
> Also sum.test can work as the number of input scalar changes.
>
> Many thanks in advance!
>
> -sean
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list