[R] merge table rows (\multirow)

Gabor Grothendieck ggrothendieck at gmail.com
Mon Jan 12 20:10:31 CET 2009


Look at the rgroup and n.rgroup arguments of ?latex
function in Hmisc package or ?print.xtable in xtable package.

On Mon, Jan 12, 2009 at 1:48 PM, Felipe Carrillo
<mazatlanmexico at yahoo.com> wrote:
> Hi:
> This is what my table should look like:
>
> Month     Week   Estpassage    MedFL
> July-----27--------4566--------34
>    -----28--------2568--------35
>    -----29--------3287--------36
>    -----30--------4623--------37
> Aug------31--------8632--------37
>   ------32--------4236--------38
>   ------33--------7632--------39
>   ------34--------5984--------40
> Sept-----35--------1258--------40
>    -----36--------4235--------41
>    -----37--------2573--------42
>    -----38--------423---------43
> I don't want to reshape my dataset, I basically want a latex table showing only one value on the first column instead of repeating the  month over and over. I know this can be done with \multirow if the table is created manually. Since this table is created dynamically on the fly I don't know how to use \multirow like that. Hope is clear. Thanks
>
>
> --- On Mon, 1/12/09, Dieter Menne <dieter.menne at menne-biomed.de> wrote:
>
>> From: Dieter Menne <dieter.menne at menne-biomed.de>
>> Subject: Re: [R] merge table rows (\multirow)
>> To: r-help at stat.math.ethz.ch
>> Date: Monday, January 12, 2009, 12:41 AM
>> Felipe Carrillo <mazatlanmexico <at> yahoo.com>
>> writes:
>>
>> > I need help merging rows.
>> > I am trying to merge the 'Month' column using
>> \multirow. For example for the
>> column 'Week' I want July to be
>> > merged into one row(weeks 27,28,29,30) and so on for
>> the following weeks.
>> > Below, I am creating a PDF using Sweave,
>> MikTex,R-2.8.1 and windows XP to show
>> an example.
>>
>>
>> I don't fully understand how the table should look
>> like, mainly
>> how the Week display should look like. I suggest that you
>> try to
>> not do the main formatting in latex/xtable, but rather use
>> function reshape or package reshape (below). The following
>> should give you a starter, I know it is not fully what you
>> want.
>>
>> Dieter
>>
>>
>> sampDat <- "Month Week Estpassage MedFL
>> July 27       665             34
>> July 28       2232           35
>> July 29       9241           35
>> July 30       28464           35
>> Aug  31       41049           35
>> Aug 32       82216           35
>> Aug 33       230411      35
>> Aug 34       358541      35
>> Sept 35       747839      35
>> Sept 36       459682      36
>> Sept 37       609567      36
>> Sept 38       979475      36
>> Sept 39       837189      36"
>> DF <- read.table(textConnection(sampDat), header = TRUE)
>>
>> library(reshape)
>> DFm = melt(DF,id=c("Month","Week"))
>> cast(DFm,variable~Month+Week)
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list