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. o
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-tp4702709
Thanks,
After posting I came across this page:
http://www.r-bloggers.com/concatenating-a-list-of-data-frames/
rbindlist seems to be a pretty good solution.
On Mon, 2015-02-02 at 16:09 -0500, dan wang wrote:
> How about this,
>
>
> t <- lapply(a,function(x){colnames(x)=c("A","B");return(x)})
> d
How about this,
t <- lapply(a,function(x){colnames(x)=c("A","B");return(x)})
do.call(rbind,t)
On Mon, Feb 2, 2015 at 4:00 PM, Tom Wright wrote:
> Hi all,
>
> I'm trying to avoid loops (no real reason, just as an exercise).
>
> Given a list:
>
> list(data.frame(a=1:3,b=letters[1:3]),data.frame(x
Hi all,
I'm trying to avoid loops (no real reason, just as an exercise).
Given a list:
list(data.frame(a=1:3,b=letters[1:3]),data.frame(x=1:5,b=LETTERS[1:5]))
Is there an easy way to collapse this to a single dataframe
result<-data.frame(a=c(1:3,1:5),b=c(letters[1:3],LETTERS[1:5]))
Thanks
_
5 matches
Mail list logo