Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change column heading using xtable in R?

Tags:

r

xtable

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?

like image 897
radiobrain77 Avatar asked Sep 27 '15 08:09

radiobrain77


1 Answers

xtable inherits data.frame.

So,

library(xtable)
xt <- xtable(tableData)

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

will work.

like image 199
Veera Avatar answered Nov 11 '22 01:11

Veera