[R] convert list to data frame

Judy Chung cp3942 at gmail.com
Mon Dec 5 13:08:54 CET 2005


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!!




More information about the R-help mailing list