首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用stargazer加宽柱子?

使用stargazer加宽柱子?
EN

Stack Overflow用户
提问于 2020-10-09 10:50:29
回答 1查看 68关注 0票数 0

所以我用stargazer制作了一个回归系数表,但我不知道如何使列更宽。

代码语言:javascript
复制
stargazer(fit2, fit3, type="html",
          dep.var.labels=c(""),
          covariate.labels=c("PVI","Research Level","Minority Serving Institution", "Women's College", "Prestige","Control Level (private = 1)", "Intercept 1", "Intercept 2"), keep.stat = "all", 
          title =  "Table 1. Ordered Logit Estimates of Chicago Statement Endorsement",
          ord.intercepts = TRUE,
          column.sep.width = "20pt",
          out="models.htm")

这是我的代码。不管我为column.sep.width设置了什么值,列都不会移动。

EN

回答 1

Stack Overflow用户

发布于 2020-10-09 13:18:03

带有type="html"stargazer返回html文本。您可以插入html样式,例如,固定列宽的html样式,例如<col width="20">...<col width="20">

代码语言:javascript
复制
library(stargazer)

linear.1 <- lm(rating ~ complaints + privileges + learning 
               + raises + critical, data=attitude)
linear.2 <- lm(rating ~ complaints + privileges + learning, data=attitude)

attitude$high.rating <- (attitude$rating > 70)
probit.model <- glm(high.rating ~ learning + critical + advance, data=attitude,
                    family = binomial(link = "probit"))

tbl <- stargazer(linear.1, linear.2, probit.model, title="Regression Results",
          type="html")

set_html_tbl_widths <- function(stargazer_html_obj, 
                                width_left=30, 
                                width_cols=rep(20, num_cols), 
                                num_cols=3, filename=NULL) {
  html_line <- c(paste0('<col width=',as.character(width_left),'>'))
  num_cols <- length(width_cols)
  for (col in 1:num_cols) {
    html_line <- append(html_line,
                        paste0('<col width=',as.character(width_cols[col]),'>'))
  } 
  new_html <- c(stargazer_html_obj[1:2], html_line, 
                stargazer_html_obj[3:length(stargazer_html_obj)])

  if (!is.null(filename)) {
    write(new_html,    
          file=filename)
  }
  return(new_html)
}

set_html_tbl_widths(tbl, 
                    filename="models.html")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64273278

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档