Greetings, I have a data set look like this:> print(MyResult)2 5 9 10 11 13 mean 6.108394 3.272211e+01 3.951703e+02 2.086217e+03 79.838867 2.592272e+04 median 1.288889 2.743511e+00 4.061491e+00 4.943710e+01 -2.821667 -3.040625e+00 var 2885.350595 2.343144e+05 1.022680e+06 1.200589e+07 365179.508831 3.363738e+09 sd 53.715460 4.840603e+02 1.011276e+03 3.464952e+03 604.300843 5.799774e+04 valid.n 83501.000000 2.699000e+03 2.600000e+01 1.000000e+01 491.000000 5.000000e+00 14 17 19 20 21 mean 226.58561 273.2301 1611.224 620.8836 3608.207 median 51.68978 56.7179 1266.557 140.8548 459.320 var 758255.12696 485670.6679 2393157.095 1232059.4957 38426150.479 sd 870.77846 696.9008 1546.983 1109.9818 6198.883 valid.n 118.00000 90.0000 58.000 77.0000 15.000 attr(,"class") [1] "dstat" The above data set was generated from brkdn function and the numbers 2, 5, and etc. indicate the levels in my breakdown. 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 How can I do it? Thanks in advance for your help, Willa This message contains confidential information and is in...{{dropped:8}}
Is this what you want:> x <- data.frame(a=1:10,b=1:10) > xa b 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6 7 7 7 8 8 8 9 9 9 10 10 10> t(x)[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] a 1 2 3 4 5 6 7 8 9 10 b 1 2 3 4 5 6 7 8 9 10>On Mon, Jul 14, 2008 at 5:40 PM, Willa Wei <wwei at dataquick.com> wrote:> > Greetings, > > I have a data set look like this: > >> print(MyResult) > 2 5 9 10 > 11 13 > mean 6.108394 3.272211e+01 3.951703e+02 2.086217e+03 > 79.838867 2.592272e+04 > median 1.288889 2.743511e+00 4.061491e+00 4.943710e+01 > -2.821667 -3.040625e+00 > var 2885.350595 2.343144e+05 1.022680e+06 1.200589e+07 > 365179.508831 3.363738e+09 > sd 53.715460 4.840603e+02 1.011276e+03 3.464952e+03 > 604.300843 5.799774e+04 > valid.n 83501.000000 2.699000e+03 2.600000e+01 1.000000e+01 > 491.000000 5.000000e+00 > 14 17 19 20 21 > mean 226.58561 273.2301 1611.224 620.8836 3608.207 > median 51.68978 56.7179 1266.557 140.8548 459.320 > var 758255.12696 485670.6679 2393157.095 1232059.4957 38426150.479 > sd 870.77846 696.9008 1546.983 1109.9818 6198.883 > valid.n 118.00000 90.0000 58.000 77.0000 15.000 > attr(,"class") > [1] "dstat" > > The above data set was generated from brkdn function and the numbers 2, > 5, and etc. indicate the levels in my breakdown. 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 > > > How can I do it? > > Thanks in advance for your help, > Willa > > > This message contains confidential information and is ...{{dropped:18}}
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