[R] Table to Data Frame

Ko-Kang Kevin Wang k.wang at auckland.ac.nz
Thu Jun 10 12:17:22 CEST 2004


[Forwarding on behalf of a colleague]

She's got a list with several tables:
> tab <- list()
> for(i in 1:6) {
+ tab[[i]] <- table(freq[i])
+ }
> tab
[[1]]

   0 0.17  0.3  0.5    1  2.5    3    4
 196    2    5    1    5    2    5    2

[[2]]

   0 0.17  0.3    1  2.5    3    4
 199    1    3    6    2    6    1

[[3]]

  0 0.5
217   1

[[4]]

  0 2.5
216   2

[[5]]

   0 0.17  0.3  0.5    1  2.5    3    4
 207    1    1    1    1    2    4    1

[[6]]

   0 0.17    3
 216    1    1


And would like to convert to a data frame, like:

    0   0.17  0.3  0.5  1
196        2     5     1  5
199        1     3     0  6
217        0     0     1   0
[snip]


Basically down the columns she'd like to have the counts.  But because each
table in the list has got different number of columns, I've been unable to
convert them into a data frame for her.

Any help would be greatly appreciated!

Cheers,

Kevin




More information about the R-help mailing list