[R] convert 'list' to 'vector'?

Liviu Andronic landronimirc at gmail.com
Thu Aug 11 22:13:34 CEST 2011


On Wed, Aug 10, 2011 at 11:39 PM, David Winsemius
<dwinsemius at comcast.net> wrote:
>> is.vector(x)
> [1] TRUE
>
> You probably didn't realize that lists _are_ vectors before this.
>
Nice to know.


> Hopefully this expected invitation to grilling will not result in severe
> burns. I note that one of the *apply family would have been successful in
> returning the desired object in conjunction with c() :
>
>> rapply(x, c)
>  [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l"
>
> `rapply` is designed to do a complete traversal of the list structure and
> its default "how" argument is "unlist". It was linked from the page where
> you were looking at `simplify2array`.
>
This also does the job nicely. As does

> c(x, recursive=T)
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l"

per Peter's suggestion. Thanks all for all the solutions.

Regards
Liviu



More information about the R-help mailing list