Search code examples
rxtable

How to change column heading using xtable in R?


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?


Solution

  • xtable inherits data.frame.

    So,

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

    will work.