[R] merge table rows (\multirow)

Dieter Menne dieter.menne at menne-biomed.de
Mon Jan 12 09:41:52 CET 2009


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.

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)




More information about the R-help mailing list