[R] Convert data set to data frame
Jim Lemon
jim at bitwrit.com.au
Wed Jul 16 01:00:06 CEST 2008
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
More information about the R-help
mailing list