8

I have the following piece of code:

tableData <- head(original_table[,c("column1",
                                    "column2",
                                    "column3")])
library(xtable)
xt <- xtable(tableData)
print(xt,type="html")

The 'original_table' object is a table where the columns have very awkward names which I do not want in the final output from printing the xtable.

I have a lot of code using the 'original_table' object which comes after the xtable is created. So I do not want to change the column headings in the original table.

How can I change the column headings using xtable so they can appear as something like 'Height','Width' and 'Breadth' in my table output?

radiobrain77
  • 613
  • 1
  • 6
  • 19
  • 1
    Is changing the column names of the tabledata an option? – Heroka Sep 27 '15 at 08:43
  • you could just rename `tableData` directly before you create `xtable` if you are using `original_table` afterwards, and not `tableData`: `names(tableData) <- c("Height", "Width", "Breadth")` – Thomas K Sep 27 '15 at 08:44
  • 1
    Admittedly it is an option. I am trying to avoid adding code in multiple places, so I would prefer to be able to do it via the xtable. – radiobrain77 Sep 27 '15 at 08:45

1 Answers1

15

xtable inherits data.frame.

So,

library(xtable)
xt <- xtable(tableData)

names(xt) <- c('Height','Width','Breadth' )

will work.

Veera
  • 861
  • 1
  • 9
  • 18