[R] collapse a list of dataframes

William Dunlap wdunlap at tibco.com
Wed Feb 4 00:34:21 CET 2015


I don't think that worked as OP would like it too - all columns of the
output
are factors.
>
 data.frame(rbind(as.matrix(data.frame(a=1:3,b=letters[1:3])),as.matrix(data.frame(x=1:5,b=LETTERS[1:5]))))
  a b
1 1 a
2 2 b
3 3 c
4 1 A
5 2 B
6 3 C
7 4 D
8 5 E
> str(.Last.value)
'data.frame':   8 obs. of  2 variables:
 $ a: Factor w/ 5 levels "1","2","3","4",..: 1 2 3 1 2 3 4 5
 $ b: Factor w/ 8 levels "a","A","b","B",..: 1 3 5 2 4 6 7 8

If you want the retain the types of the columns, leave out those as.matrix()
calls (and then there is no need to call data.frame on rbind's output).



Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Tue, Feb 3, 2015 at 12:56 PM, JS Huang <js.huang at protective.com> wrote:

> Hi,
>
>   The following worked.
>
> >
> data.frame(rbind(as.matrix(data.frame(a=1:3,b=letters[1:3])),as.matrix(data.frame(x=1:5,b=LETTERS[1:5]))))
>   a b
> 1 1 a
> 2 2 b
> 3 3 c
> 4 1 A
> 5 2 B
> 6 3 C
> 7 4 D
> 8 5 E
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/collapse-a-list-of-dataframes-tp4702709p4702773.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list