An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090309/6e346562/attachment-0002.pl>
How to write a function that accepts unlimited number of input arguments?
4 messages · Sean Zhang, Baptiste Auguie, Gabor Grothendieck +1 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090309/dced4fd9/attachment-0002.pl>
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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20090310/5c04224b/attachment-0002.pl>