How can I create report quality tables from R?

If I have the following data file called result

> result Name CV LCB UCB 1 within 2.768443 1.869964 5.303702 2 between 4.733483 2.123816 18.551051 3 total 5.483625 3.590745 18.772389 > dput(result,"") structure(list(Name = structure(c("within", "between", "total" ), .rk.invalid.fields = list(), .Label = character(0)), CV = c(2.768443, 4.733483, 5.483625), LCB = c(1.869964, 2.123816, 3.590745), UCB = c(5.303702, 18.551051, 18.772389)), .Names = c("Name", "CV", "LCB", "UCB" ), row.names = c(NA, 3L), class = "data.frame") 

What is the best way to present this data? Ideally, I need an image file that can be inserted into a report, or perhaps an HTML file to represent a table?

Additional points for setting the number of significant digits.

+4
source share
4 answers

I would use xtable . I usually use it with Sweave.

 library(xtable) d <- data.frame(letter=LETTERS, index=rnorm(52)) d.table <- xtable(d[1:5,]) print(d.table,type="html") 

If you want to use it in a Sweave document, you should use it like this:

 <<label=tab1,echo=FALSE,results=tex>>= xtable(d, caption = "Here is my caption", label = "tab:one",caption.placement = "top") @ 
+8
source

For the table aspect, the xtable problem arises , as it can create LaTeX output (which you can use through Sweave for professional reports), as well as html.

If you combine this in Sweave with fancy graphs (see other questions for ggplot examples), you're almost there.

+7
source
 library(ggplot2) ggplot(result, aes(x = Name, y = CV, ymin = LCB, ymax = UCB)) + geom_errorbar() + geom_point() ggplot(result, aes(x = Name, y = CV, ymin = LCB, ymax = UCB)) + geom_pointrange() 
+2
source

It is impossible to comment on the creation of a beautiful table, but in order to establish meaningful numbers, the simplest thing that needs to be done (for example, note) is to move the name to the names of outlets and around everything.

 #Set the rownames equal to Name - assuming all unique rownames(result) <- result$Name #Drop the Name column so that round() can coerce #result.mat to a matrix result.mat <- result[ , -1] round(result.mat, 2) #Where 2 = however many sig digits you want. 

This is not a very reliable solution - not unique values โ€‹โ€‹of the name could break it, as I think, in the same way as other non-numeric columns. But to create a table like your example is a trick.

0
source

All Articles