Re: [R] unlist & dataframes

From: David Freedman <3.14david_at_gmail.com>
Date: Thu, 06 Nov 2008 03:02:37 -0800 (PST)

try

newdata=do.call(rbind,l)

David Freedman, Atlanta

Naira wrote:
>
> Dear all,
>
> I would like to know whether it is possible to unlist elements and keep
> the original format of the data.
> To make it more clear, let me give an exemple:
> I have a list l of dataframes that I created with apply but which looks
> like this:
>
> x1=data.frame(Name=LETTERS[1:2],Age=1:2)
> x2=data.frame(Name=LETTERS[3:4],Age=3:4)
> l=list(x1,x2)
> l
> [[1]]
> Name Age
> 1 A 1
> 2 B 2
>
> [[2]]
> Name Age
> 1 C 3
> 2 D 4
>
> I would like to unlist l to create a dataframe with 2 columns and 4 rows
> but keeping the format of Name (character) and Age (numeric).
>
> Now when I unlist l, I obtain :
>
> unlist(l)
> Name1 Name2 Age1 Age2 Name1 Name2 Age1 Age2
> 1 2 1 2 1 2 3 4
>
> Is there a way to at least obtain something like
> A 1 B 2 C 3 D 4 as result from the unlist??
>
> Thanks a lot for your replies
> Naira
>
>
>



David Freedman
Atlanta
-- 
View this message in context: http://www.nabble.com/unlist---dataframes-tp20358993p20359063.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org 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.
Received on Thu 06 Nov 2008 - 11:06:06 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 06 Nov 2008 - 11:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive