Re: [R] Convert data set to data frame

From: Jim Lemon <jim_at_bitwrit.com.au>
Date: Wed, 16 Jul 2008 09:00:06 +1000

On Mon, 2008-07-14 at 14:40 -0700, Willa Wei wrote:
> .... Now, I want to have a
> data frame looks like shown below so that I can save it into my
> database:
>
> Level mean median var sd valid.n
> 2 6.11 1.29 2885 53.72 8.35e+04
> 5 32.72 2.74 2.343e+05 484.1 2699
> 9 395.2 4.06 1.023e+06 1011 26
> 10 2086 49.44 1.201e+07 3465 10
> 11 79.84 -2.82 3.652e+05 604.3 491
> 13 2.592e+04 -3.04 3.364e+09 5.8e+04 5
> 14 226.6 51.69 7.583e+05 870.8 118
> 17 273.2 56.72 4.857e+05 696.9 90
> 19 1611 1267 2.393e+06 1547 58
> 20 620.9 140.8 1.232e+06 1110 77
> 21 3608 459.3 3.843e+07 6199 15
>
Hi Willa,
If you only have one level of breakdown, the result will be a matrix, but you will have to remove the class:

my.new.breakdown<-as.data.frame(unclass(t(my.old.breakdown)))

For multilevel breakdowns, you will have to create a function like:

brkdn2tdf<-function(x) return(as.data.frame(unclass(t(x))))

and then use rapply to step through the list.

Jim



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 15 Jul 2008 - 22:58:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 15 Jul 2008 - 23:32:04 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive