[R] How to write a function that accepts unlimited number of input arguments?
ggrothendieck at gmail.com
Mon Mar 9 22:59:25 CET 2009
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
> Also sum.test can work as the number of input scalar changes.
> Many thanks in advance!
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> 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