Skip to content

merge table rows (\multirow)

4 messages · Dieter Menne, Felipe Carrillo

#
Hi:
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.


\documentclass[11pt]{article}
\usepackage{longtable,verbatim}
\title{How to implement multirow with Sweave}
\begin{document}
\maketitle
<<dataAnalysis.R,echo=FALSE>>=
sampDat <- "Month, Week, Est.passage, Med.FL
July 27	   665	         34
July 28	   2,232	       35
July 29	   9,241	       35
July 30	   28,464	       35
Aug  31	   41,049	       35
Aug 32	   82,216	       35
Aug 33	   230,411      35
Aug 34	   358,541      35
Sept 35	   747,839      35
Sept 36	   459,682      36
Sept 37	   609,567      36
Sept 38	   979,475      36
Sept 39	   837,189      36"
DF <- read.table(textConnection(sampDat), header = TRUE)
attach(DF)
@
\begin{verbatim}
Using Hmisc.....
\end{verbatim}
<<tab.R,echo=FALSE,results=tex>>=
library(Hmisc)
mytab <- data.frame(DF)
latex(DF,label="tab:hola",longtable=FALSE,caption='Sample table.')
@
\begin{verbatim}
Or with xtable....
\end{verbatim}
<<tab.RR,echo=F,results=tex>>=
library(xtable)
table2 <- data.frame(DF)
table2 <- xtable(DF,label='tab2',caption='table 2 with xtable',digits=0)
print(table2,floating=FALSE)
@
\end{document}

Felipe D. Carrillo  
Supervisory Fishery Biologist  
Department of the Interior  
US Fish & Wildlife Service  
California, USA
#
Felipe Carrillo <mazatlanmexico <at> yahoo.com> writes:
column 'Week' I want July to be
an example.

Thanks for the goodexample (Note to the "you did not quote completely" 
complainants: please use a thread reader to see the OP. This list
is clutter with too many > >> >>>).

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.

I had some problems with the commas in you data set, so
I removed these.

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)
#
Felipe Carrillo wrote:
.. Example removed and partially regenerated below

Another try; had a bad hour this morning, too many typos. 
This comes closer to what you want, but not exactly. 
You might try to manually call format.df which is implicitly 
called in latex, and massage that.
Again, I do not know if this is easier with xtable.

If you want to post latex samples, it is not really
necessary to include it in Sweave. The example
below works fine for testing.

Dieter


library(Hmisc)
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)
row.names(DF)=DF$Week
latex(DF[,-2],label="tab:hola",longtable=FALSE,caption='Sample table.',
  rowname="",
  rgroup=unique(DF$Month),n.rgroup=table(DF$Month))
#
Thanks a lot Dieter, I'll play a little bit with it. Also thanks for the hint on how to post a latex reproducible example.
--- On Mon, 1/12/09, Dieter Menne <dieter.menne at menne-biomed.de> wrote: