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. 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
Tom, If you are wanting PDF as your output, are you wanting to use LaTeX or Markdown with knitr. LaTeX will give you more options. You have not shown an attempt to use either for your table construction. Can you define what you mean by pretty? Is it the underscores in the column names that are the problem? Mark> On Nov 25, 2014, at 2:12 PM, Tom Wright <tom at maladmin.com> 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. > > 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.NOTICE: This E-Mail (including attachments) is confidential and may be legally privileged. It is covered by the Electronic Communications Privacy Act, 18 U.S.C.2510-2521. If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution or copying of this communication is strictly prohibited. Please reply to the sender that you have received this message in error, then delete it.
Hi Mark, It is the underscores that are my issue, I'd prefer multiple level row titles: |ID1 |ID2 |Time1 |Time2 |Time1 |Time2 |OD |OS |OD |OS|OD |OS |OD |OS Height | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 Weight| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 Currently I'm using markdown in r-studio. And yes, I know the same information is in the dcast solution but I'm trying to convince people R is an alternative to excel. On Tue, Nov 25, 2014 at 3:37 PM, Mark Sharp <msharp at txbiomed.org> wrote:> Tom, > > If you are wanting PDF as your output, are you wanting to use LaTeX or > Markdown with knitr. LaTeX will give you more options. You have not shown > an attempt to use either for your table construction. Can you define what > you mean by pretty? Is it the underscores in the column names that are the > problem? > > Mark > > On Nov 25, 2014, at 2:12 PM, Tom Wright <tom at maladmin.com> 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. > > > > 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. > > > NOTICE: This E-Mail (including attachments) is confidential and may be > legally privileged. It is covered by the Electronic Communications Privacy > Act, 18 U.S.C.2510-2521. If you are not the intended recipient, you are > hereby notified that any retention, dissemination, distribution or copying > of this communication is strictly prohibited. Please reply to the sender > that you have received this message in error, then delete it. >[[alternative HTML version deleted]]
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.
Thanks Duncan, Dropping the extra columns might be the way forward. I'm sure I can work out how to embed latex into a markdown document ;-) On Tue, Nov 25, 2014 at 4:37 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:> 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. >> > >[[alternative HTML version deleted]]
Franzini, Gabriele [Nervianoms]
2014-Nov-26 12:35 UTC
[R] Presentation tables in R (knitr)
I found also knitr + html + the ReporteRs package a good combination, and less intimidating than Latex. Have a look at their FlexTable tool. HTH, Gabriele -----Original Message----- From: Tom Wright [mailto:tom at maladmin.com] Sent: Tuesday, November 25, 2014 9:12 PM To: r-help at r-project.org Subject: [R] Presentation tables in R (knitr) 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. 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