hughjonesd / huxtable

An R package to create styled tables in multiple output formats, with a friendly, modern interface.
http://hughjonesd.github.io/huxtable
Other
322 stars 28 forks source link

Group estimates in regression table #162

Closed ChrisWaloszek closed 4 years ago

ChrisWaloszek commented 4 years ago

Would it be possible to group together certain estimates to distinguish between treatment and control variables in a regression? Below an attempt with rowspan() which did not get very far (first rows for my somehow no longer shown in the table).

  data(diamonds, package = "ggplot2")
  diamonds <- diamonds[1:100,]

  lm1 <- lm(price ~ carat + depth, diamonds)
  lm2 <- lm(price ~ depth + factor(color, ordered = FALSE), diamonds)
  lm3 <- lm(log(price) ~ carat + depth, diamonds)

  color_names <- grep("factor", names(coef(lm2)), value = TRUE)
  names(color_names) <- gsub(".*)(.)", "Color: \\1", color_names)

  hux <- huxreg(lm1, lm2, lm3, coefs = c("Carat" = "carat", "Depth" = "depth", color_names))
  rowspan(hux)[1, 1:4] <- 4
  hux
hughjonesd commented 4 years ago

Certainly possible, but I don't plan to include facilities within huxreg to do this. It is simpler to use standard huxtable editing.

ChrisWaloszek commented 4 years ago

Thank you for the info. How would that look alike for the above example?

hughjonesd commented 4 years ago

See the manual for how to insert rows and columns. For your example, I'm not sure what you are trying to do, but indeed if you make rowspan 4 for the top row, then rows 2-4 will be hidden.