[R] output formatting

Pele drdionc at yahoo.com
Thu Mar 5 05:32:07 CET 2009


Hi Kingsford - this is exactly what I am looking for...
Many thanks!!


Kingsford Jones wrote:
> 
> I'm guessing you processed a data frame with the 'by' function.
> Rather than restructuring the by output, try using a different
> function on your data frame.  For example
> 
>> #install.packages(doBy)
>> summaryBy(breaks ~ tension + wool, data=warpbreaks, FUN=sum)
>   tension wool breaks.sum
> 1       L    A        401
> 2       L    B        254
> 3       M    A        216
> 4       M    B        259
> 5       H    A        221
> 6       H    B        169
> 
> as opposed to
> 
>> with(warpbreaks, by(breaks, list(tension,wool), sum))
> : L
> : A
> [1] 401
> ------------------------------------------------------------------------------
> : M
> : A
> [1] 216
> ------------------------------------------------------------------------------
> : H
> : A
> [1] 221
> ------------------------------------------------------------------------------
> : L
> : B
> [1] 254
> ------------------------------------------------------------------------------
> : M
> : B
> [1] 259
> ------------------------------------------------------------------------------
> : H
> : B
> [1] 169
> 
> 
> hth,
> Kingsford Jones
> 
> On Wed, Mar 4, 2009 at 8:17 PM, Pele <drdionc at yahoo.com> wrote:
>>
>> Hi R users,
>>
>> I have an R object with the following attributes:
>>
>>> str(sales.bykey1)
>>  'by' int [1:3, 1:2, 1:52] 268 79 118 359 87 147 453 130 81 483 ...
>>  - attr(*, "dimnames")=List of 3
>>  ..$ GROUP: chr [1:3] "III" "II" "I"
>>  ..$ year           : chr [1:2] "2006" "2007"
>>  ..$ week           : chr [1:52] "1" "2" "3" "4" ...
>>  - attr(*, "call")= language by.data.frame(data = vars, INDICES = bykey1,
>> FUN = sum)
>>
>>> sales.bykey1
>> ---------------
>> GROUP: III
>> year: 2007
>> week: 51
>> [1] 64
>> ---------------
>> GROUP: II
>> year: 2007
>> week: 51
>> [1] 17
>> ---------------
>> GROUP: I
>> year: 2007
>> week: 51
>> [1] 21
>> ---------------
>> GROUP: III
>> year: 2006
>> week: 52
>> [1] 14
>> ---------------
>> GROUP: II
>> year: 2006
>> week: 52
>> [1] 62
>> --------------
>> GROUP: I
>> year: 2006
>> week: 52
>> [1] 10
>>
>>
>> Can anyone share the most efficient way to convert the output
>> (sales.bykey1)
>> above to look like this:
>>
>>
>> GROUP   Year    week    sales
>> III     2007    51      64
>> II      2007    51      17
>> I       2007    51      21
>> III     2006    52      14
>> II      2006    52      62
>> I       2006    52      10
>>
>> Many thanks in advance for any help!
>> --
>> View this message in context:
>> http://www.nabble.com/output-formatting-tp22344554p22344554.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>>
> 
> ______________________________________________
> 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/output-formatting-tp22344554p22345085.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list