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:> I need help merging rows. > I am trying to merge the 'Month' column using \multirow. For example for thecolumn '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 showan 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:> > 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. > >.. 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)) -- View this message in context: http://www.nabble.com/merge-table-rows-%28%5Cmultirow%29-tp21408818p21417983.html Sent from the R help mailing list archive at Nabble.com.
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)
Reasonably Related Threads
- Time Series Graphics - "cannot plot more than 10 series"
- Optimize for loop / find last record for each person
- Have a function like the "_n_" in R ? (Automatic count function )
- Problem in appending a row to *.csv file
- Dataframes: conditional calculations per row .