[R] convert list to data frame

Petr Pikal petr.pikal at precheza.cz
Mon Dec 5 13:55:29 CET 2005


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 at gmail.com>
To:             	r-help at 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 at 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 at precheza.cz




More information about the R-help mailing list