[R] not understanding a do.call
Tony Plate
tplate at acm.org
Wed Oct 18 19:45:06 CEST 2006
Suppose you have a list of equal-length numeric vectors and you want to
bind them together in a matrix. You want to a piece of code that will
work no matter how many vectors are in the list. That's what this
construct with do.call() is useful for,
e.g.:
> a <- 1:3
> b <- 4:6
> c <- 7:9
> x1 <- list(a=a,b=b)
> x2 <- list(a=a,b=b,c=c)
> do.call("cbind", x1)
a b
[1,] 1 4
[2,] 2 5
[3,] 3 6
> do.call("cbind", x2)
a b c
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
>
-- Tony Plate
Leeds, Mark (IED) wrote:
> I did a ?do.call but i don't think i understand it.
>
> if a, b,c,d are numeric vectors then could someone explain the
> difference between
>
> do.call("cbind",list(a,b,c,d))
>
> and cbind(a,b,c,d).
>
> or point to an archive on it.
>
> the return value of cbind is a matrix or dataframe depending on what is
> sent in but i don't
> understand wheen it would be useful to use do.call. i realize it takes a
> list but that's
> all i know about why one use it ? thanks.
> --------------------------------------------------------
>
> This is not an offer (or solicitation of an offer) to buy/sell the securities/instruments mentioned or an official confirmation. Morgan Stanley may deal as principal in or own or act as market maker for securities/instruments mentioned or may advise the issuers. This is not research and is not from MS Research but it may refer to a research analyst/research report. Unless indicated, these views are the author's and may differ from those of Morgan Stanley research or others in the Firm. We do not represent this is accurate or complete and we may not update this. Past performance is not indicative of future returns. For additional information, research reports and important disclosures, contact me or see https://secure.ms.com/servlet/cls. You should not use e-mail to request, authorize or effect the purchase or sale of any security or instrument, to send transfer instructions, or to effect any other transactions. We cannot guarantee that any such requests received vi
a !
> e-mail will be processed in a timely manner. This communication is solely for the addressee(s) and may contain confidential information. We do not waive confidentiality by mistransmission. Contact me if you do not wish to receive these communications. In the UK, this communication is directed in the UK to those persons who are market counterparties or intermediate customers (as defined in the UK Financial Services Authority's rules).
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
More information about the R-help
mailing list