rreportingpresentationsweave

How can I produce report quality tables from R?


If I have the following dataframe 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 nicely? Ideally I'd like an image file that can be pasted into a report, or possibly an HTML file to represent the table?

Extra points for setting number of significant figures.


Solution

  • 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 would use it like so:

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