[R] dots expansion

Liaw, Andy
Tue, 03 Aug 2004 11:58:24 -0000

Duncan already gave the answer.  Here's a bit more detail:

rbindGroup <- function(...) {
    theList <- list(...)
    nGroup <- length(theList)
    size <- sapply(theList, nrow)
    result <- rbind(...)
    result <- cbind(result, rep(1:nGroup, each=size)
    result
}

You probably want to add more error checks (like making sure all arrays have
the same number of columns).

HTH,
Andy

> From: Viet Nguyen
>
> Hi list,
>
> I'm trying to write a function similar to rbind, except that needs to
> add a factor to each component array before rbinding them together so
> that the rows from different arrays are distinguishable.
>
> The problem that arose is how to loop through arguments in the dots
> "..." list. I need to get a hand on each of them but don't
> know how many
> of them there are and what their names are.
>
> It'd be useful if I could look at how rbind(...) or c(...) do
> this but
> they are both Internal functions.
>
> Thanks in anticipation of help!
>
> Regards,
> viet
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>