Re: [S] Changing a list to a vector

Bill Venables (wvenable@attunga.stats.adelaide.edu.au)
Wed, 20 May 1998 08:39:00 +0930


Alan Donald writes:
> This is rather a simple question that I remember running into
> about a year ago and solving -- but I cannot remember how I
> did it.
>
> I have a list whose components are numeric vectors of various
> lengths. What I want to do is to strip the "list" structure
> from the object so that I get a vector consisting of all the
> components glued together. This is part of a program, so I
> could -- I guess -- write a little program that trudges its
> way through the list tacking vectors on to the end of a long
> train of numbers. But I think there is a function in Splus
> that will do this for me quickly. Searches through the Splus
> 3.3 and 4 help files and manuals have turned up nothing. Must
> be looking under the wrong word.

The "I could kick myself" answer is, of course,

> one.big.vector <- unlist(list.of.vectors).

It then occurred to me that there is another answer almost as
simple and somewhat more instructive:

> one.big.vector <- do.call("c", list.of.vectors)

Bill
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news