Re: [R] convert list to data frame

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Mon 05 Dec 2005 - 23:55:29 EST


Hi

change

rownames(your.frame)<-1:dim(yourframe)[1]

HTH
Petr

On 5 Dec 2005 at 20:08, Judy Chung wrote:

Date sent:      	Mon, 5 Dec 2005 20:08:54 +0800
From:           	Judy Chung <cp3942@gmail.com>
To:             	r-help@stat.math.ethz.ch
Subject:        	[R] convert list to data frame

> Dear R users:
>
> I've a list containing parameters (A , B & C), and I want create a
> data frame using data in these list.
> > coffee
> [[1]]
> A B C
> 1 1 0.5 7.78
> 2 1 1.0 6.06
> 3 1 2.0 3.67
> 4 1 4.0 1.35
> 5 1 6.0 0.49
> 6 1 8.0 0.18
>
> [[2]]
> A B C
> 1 2 5 7.78
> 2 2 10 6.06
> 3 2 20 3.67
> 4 2 40 1.35
> 5 2 60 0.49
> 6 2 80 0.18
>
> > as.data.frame(do.call("rbind",coffee))
> A B C
> 1 1 0.5 7.78
> 2 1 1.0 6.06
> 3 1 2.0 3.67
> 4 1 4.0 1.35
> 5 1 6.0 0.49
> 6 1 8.0 0.18
> 11 2 5 7.78
> 21 2 10 6.06
> 31 2 20 3.67
> 41 2 40 1.35
> 51 2 60 0.49
> 61 2 80 0.18
>
> But I want the form like this:
> A B C
> 1 1 0.5 7.78
> 2 1 1.0 6.06
> 3 1 2.0 3.67
> 4 1 4.0 1.35
> 5 1 6.0 0.49
> 6 1 8.0 0.18
> 7 2 5 7.78
> 8 2 10 6.06
> 9 2 20 3.67
> 10 2 40 1.35
> 11 2 60 0.49
> 12 2 80 0.18
>
> How would I do this?
> Please give me some comments.
> Thanks in advance!!
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal@precheza.cz



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Dec 06 00:06:23 2005

This archive was generated by hypermail 2.1.8 : Tue 06 Dec 2005 - 02:27:11 EST