[R] How to count the number of parameters in a function

Clément Calenge calenge at biomserv.univ-lyon1.fr
Wed Apr 9 10:09:41 CEST 2003


You can use list(...):

Myfunc<-function(...)
{
d<-list(...)
n<-length(d)
## Other instructions
return(n)
}

##  Example:

var1<-runif(20)
var2<-rnorm(20)
var3<-rpois(20, 2)
Myfunc(var1, var2, var3)

Hope this helps,

Clem.



At 08:55 09/04/2003 +0100, arnaud_amsellem at ssga.com wrote:
>I have the following function:
>Myfunc <- function(var1,var2,.....,varN)
>{ .....
>}
>In the above function I have a variable number of parameters (N>2). How can
>I count how many parameters have been entered?
>
>Any help appreciated
>
>Thanks
>
>Arno
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help



More information about the R-help mailing list