Hi all, I have a series of measurements made over different types of road surfaces and capacity that I want to summarize in tables via LaTeX. Ideally I'd like a table similar to this ( http://www.andy-roberts.net/misc/latex/tutorial4/multirow.png ) with mean/SD of the measurement broken down by road type (both surface and capacity). Ideally it would be extensible so that when I add layers of heirarchy on top the complexity does not increase exponentially (e.g. measurement by road surface/capacity by month by neighborhood), but rather take those additional levels as arguments. xtable() is a wonderful thing, but it seems to lack a method for displaying the results broken down by a factor as in the table above. One can easily write code to add lines between the segments, but then the levels are repeated for each row. Has anyone written a method for xtable() to handle this (assuming not, otherwise it'd be in the package)? Is there any way to pass a \multirow call to xtable() (assuming not, otherwise it'd be in the documentation)? If the answers to both of the above are "no," then can someone give me a pointer to a basic but thorough explanation of how generic functions and methods are structured (S3, I believe), preferably online. I tried doing this via getS3method("xtable","data.frame") and working from there, but the method merely sets up things for the generic function to render (it's likely I'm getting my terminology somewhat wrong here; please forgive) and what I want to do is beyond the bounds of modifying it in this way. I've looked through _Writing R Extensions_, but the Generic Functions and Methods chapter is only about a page long. Thanks on behalf of all the lurkers. I've learned much just by reading the daily digests over the last few weeks. Ari Ari Friedman abfriedman@gmail.com [[alternative HTML version deleted]]
See ?ftable and do RSiteSearch("latex ftable") to find some posts relevant to what you need. Chuck On Mon, 5 Nov 2007, A Friedman wrote:> Hi all, > > I have a series of measurements made over different types of road surfaces > and capacity that I want to summarize in tables via LaTeX. Ideally I'd like > a table similar to this ( > http://www.andy-roberts.net/misc/latex/tutorial4/multirow.png ) with mean/SD > of the measurement broken down by road type (both surface and capacity). > Ideally it would be extensible so that when I add layers of heirarchy on top > the complexity does not increase exponentially (e.g. measurement by road > surface/capacity by month by neighborhood), but rather take those additional > levels as arguments. > > xtable() is a wonderful thing, but it seems to lack a method for displaying > the results broken down by a factor as in the table above. One can easily > write code to add lines between the segments, but then the levels are > repeated for each row. Has anyone written a method for xtable() to handle > this (assuming not, otherwise it'd be in the package)? Is there any way to > pass a \multirow call to xtable() (assuming not, otherwise it'd be in the > documentation)? > > If the answers to both of the above are "no," then can someone give me a > pointer to a basic but thorough explanation of how generic functions and > methods are structured (S3, I believe), preferably online. I tried doing > this via getS3method("xtable","data.frame") and working from there, but the > method merely sets up things for the generic function to render (it's likely > I'm getting my terminology somewhat wrong here; please forgive) and what I > want to do is beyond the bounds of modifying it in this way. I've looked > through _Writing R Extensions_, but the Generic Functions and Methods > chapter is only about a page long. > > Thanks on behalf of all the lurkers. I've learned much just by reading the > daily digests over the last few weeks. > Ari > > Ari Friedman > abfriedman at gmail.com > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901
A point of clarification: the measurements are continuous; the road surface is discrete with four levels, and the road capacity is discrete with five levels. Each measured point has both a surface and capacity associated with it. Thanks, Ari I have a series of measurements>[[alternative HTML version deleted]]
If you look at the latex output associated with the page you posted you need to: - eliminated all repeated elements in column 1 - replace each non-repeated element, say X, which spans 3 rows, say, to \hline\multirow{3}{*}{X} - add an \hline after the last row Using the first 10 rows of the builtin Orange data frame try the following. Adjust align= appropriately for your case. DF <- head(Orange, 10) DF[[1]] <- as.character(DF[[1]]) rle.lengths <- rle(DF[[1]])$lengths first <- !duplicated(DF[[1]]) DF[[1]][!first] <- "" DF[[1]][first] <- paste("\\hline\\multirow{", rle.lengths, "}{*}{", DF[[1]][first], "}") print(xtable(DF, align = "l|r|r|r|"), include.rownames = FALSE, include.colnames = FALSE, sanitize.text.function = force, hline.after = nrow(DF) ) On Nov 5, 2007 11:31 AM, A Friedman <abfriedman at gmail.com> wrote:> Hi all, > > I have a series of measurements made over different types of road surfaces > and capacity that I want to summarize in tables via LaTeX. Ideally I'd like > a table similar to this ( > http://www.andy-roberts.net/misc/latex/tutorial4/multirow.png ) with mean/SD > of the measurement broken down by road type (both surface and capacity). > Ideally it would be extensible so that when I add layers of heirarchy on top > the complexity does not increase exponentially (e.g. measurement by road > surface/capacity by month by neighborhood), but rather take those additional > levels as arguments. > > xtable() is a wonderful thing, but it seems to lack a method for displaying > the results broken down by a factor as in the table above. One can easily > write code to add lines between the segments, but then the levels are > repeated for each row. Has anyone written a method for xtable() to handle > this (assuming not, otherwise it'd be in the package)? Is there any way to > pass a \multirow call to xtable() (assuming not, otherwise it'd be in the > documentation)? > > If the answers to both of the above are "no," then can someone give me a > pointer to a basic but thorough explanation of how generic functions and > methods are structured (S3, I believe), preferably online. I tried doing > this via getS3method("xtable","data.frame") and working from there, but the > method merely sets up things for the generic function to render (it's likely > I'm getting my terminology somewhat wrong here; please forgive) and what I > want to do is beyond the bounds of modifying it in this way. I've looked > through _Writing R Extensions_, but the Generic Functions and Methods > chapter is only about a page long. > > Thanks on behalf of all the lurkers. I've learned much just by reading the > daily digests over the last few weeks. > Ari > > Ari Friedman > abfriedman at gmail.com > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >
## I would use latex() for this example. library(Hmisc) team.dat <- ' GK Paul Robinson LB Lucus Radebe DC Michael Duberry DC Dominic Matteo RB Didier Domi MC David Natty MC Eirik Bakke MC Jody Morris FW Jamie Mcmaster ST Alan Smith ST Mark Viduka ' team <- read.table(textConnection(team.dat), col.names=c("position", "first", "last")) team$name <- paste(team$first, team$last) team <- team[c("position","name")] team team.latex <- latex(team, rowlabel="", rowname="", rgroup=c("Goalkeeper","Defenders","Midfielders","Forward","Strikers"), n.rgroup=c(1,4,3,1,2)) ## The file named in print.default(team.latex) has the complete tabular ## environment for the example. There are many more arguments for fine tuning the ## appearance of the table. -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of A Friedman Sent: Monday, November 05, 2007 11:32 AM To: r-help at r-project.org Subject: [R] xtable.by http://www.andy-roberts.net/misc/latex/tutorial4/multirow.png