Hi,
On 9 Mar 2009, at 15:32, Sean Zhang wrote:
> Dear R-helpers:
> I am an R newbie and have a question related to writing functions that
> accept unlimited number of input arguments.
it's usually through the ... argument, e.g in paste(...).
> (I tried to peek into functions such as paste and cbind, but failed, I
> cannot see their codes..)
>
simply type their name in the R prompt
> paste
function (..., sep = " ", collapse = NULL)
.Internal(paste(list(...), sep, collapse))
<environment: namespace:base>
etc...
but that's not very useful here.
> 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)
see ?Reduce for one way to do this:
add <- function(x) Reduce("+", x)
add(list(1, 2, 3))
>
> Also sum.test can work as the number of input scalar changes.
>
> Many thanks in advance!
>
> -sean
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [email protected] 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.
_____________________________
Baptiste AuguiƩ
School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK
Phone: +44 1392 264187
http://newton.ex.ac.uk/research/emag
______________________________
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.