[R] formatting column names of data frame
John Kane
jrkrideau at inbox.com
Sat May 18 18:49:39 CEST 2013
As Rainer Schuermann says, use the xtable package. Have a look at the documentation entitled xtable gallary --available at your friendly neigbourhood CRAN site and have a look at section 3.1. and it's probably a good idea to look at ?print.xtable as well
You might also what to have a look at the latex function in Hmisc.
Here is an example with "Average" in bold. It ran for me using LyX and knitr rather than Sweave.
###==================================
library( xtable )
x <- structure(list(Record = 1:3, Average = c(34L, 14L, 433L), Maximum = c(899L, 15L, 1003L)), .Names = c("Record", "Average", "Maximum"), class = "data.frame", row.names = c(NA, -3L))
names(x) <- c("Record", "\\textbf{Average}", "Maximum")
x <- xtable( x )
print( x, sanitize.text.function = function(x){x} )
###==================================
John Kane
Kingston ON Canada
> -----Original Message-----
> From: pleyshock at gmail.com
> Sent: Fri, 17 May 2013 12:53:12 -0700
> To: r-help at r-project.org
> Subject: [R] formatting column names of data frame
>
> Is there any way to format the headers of data frames, for printing?
>
> I am using Sweave to generate formatted reports. In Sweave, I read in a
> data.frame:
>
> result <- read.table(path.to.table);
>
> then display it:
>
> print.data.frame(result);
>
> This gives me what I expect in the eventual final output:
>
> Record Average Maximum
> 1 34 899
> 2 14 15
> 3 433 1003
> ... ... ...
>
> What I am hoping to do is distinguish one or more of the column headers,
> for example, I want "Average" or "Maximum" to be bold, underlined, etc.,
> just some way to make the column name stand out visually.
>
> Any idea if this is possible? Any suggestions appreciated.
>
> [[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.
____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!
More information about the R-help
mailing list