Message-ID: <5474F67E.5090203@gmail.com>
Date: 2014-11-25T21:37:02Z
From: Duncan Murdoch
Subject: Presentation tables in R (knitr)
In-Reply-To: <1416946341.1909.23.camel@tom-laptop>
On 25/11/2014 3:12 PM, Tom Wright wrote:
> Hi,
> This problem has me stumped so I thought I'd ask the experts. I'm trying
> to create a pretty summary table of some data (which patients have had
> what tests at what times). Ideally I'd like to knitr this into a pretty
> PDF for presentation.
> If anyone has pointers I'll be grateful.
>
> require(tables)
> require(reshape2)
>
> data<-data.frame('ID'=paste0('pat',c(rep(1,8),rep(2,8))),
> 'Time'=c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4),
> 'Eye'=rep(c('OS','OS','OD','OD'),4),
> 'Measure'=rep(c('Height','Weight'),8))
>
> tabular(Measure~factor(ID)*factor(Time)*factor(Eye),data)
> #All levels of Time are repeated for all IDs, I'd prefer to just show
> the relevant times.
You can drop certain rows of the table. See the last example in
?tabular. (It's possible to do logical indexing, but a little harder.
I think the vignette has an example of this...)
You can use latex() on the results, and display them in a knitr document.
Duncan Murdoch
>
> tabular(Measure~factor(ID)*Time*factor(Eye),data)
> #Time is getting collapsed by ID
>
> data$value=1
> dcast(data,Measure~ID+Time+Eye)
> #close but not very pretty
>
> ______________________________________________
> 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.