(a) One way to use the flextable package to create a table with lm() statistics while deselecting certain columns or changing the color of specific rows is to use the flextable()
function to create the table and then use the various formatting functions available in the package to customize the table.
For example, to remove a column, you can use the remove()
function and specify the column name. To change the color of a specific row, you can use the bg()
function and specify the row index and the color.
library(flextable)
lm_ft <- flextable(lm)
lm_ft <- remove(lm_ft, j = c("t value"))
lm_ft <- bg(lm_ft, i = c(1), j = 1:ncol(lm_ft), bg = "blue")
lm_ft
(b) Another way to create a table with lm() statistics is to use the stargazer
package. It allows you to easily create LaTeX, HTML, and ASCII tables from various model objects, including lm(). The package also provides options for selecting or deselecting columns, controlling the appearance of the table and more.
library(stargazer)
stargazer(lm,type = "text",
omit.stat = c("t","F"),
title = "Linear Regression Results",
dep.var.caption = "Dependent variable",
covariate.labels = c("Cyl"))