在下面的协变量标签中,我想在下标中包含P,M和C。这是我的代码:
stargazer(DD1_PT, DD1_MT, DD1_CT,
type = "text",
title = "Table 1",
out = "table1.html",
dep.var.labels.include = FALSE,
column.labels = c("Presidential", "Midterm", "Constitutional"),
model.numbers = FALSE,
order=c(4, 1, 8, 2, 9, 3, 10, 5, 6, 7),
covariate.labels=c("TimeP (1 = 2016/0 = 2012)","TimeP*Vote center", "TimeM (1 = 2018/0
= 2010)", "TimeM*Vote center", "TimeC (1 = 2017/0 = 2009)", "TimeC*Vote center"),
no.space=TRUE,
omit.stat=c("LL","ser","f"),
notes = c("Standard errors given in parentheses ", "Population scaled to 1,000,000 and
income scaled to 10,000"),
notes.align = "r"))
关于我该怎么做的任何想法?
谢谢!
答案 0 :(得分:0)
您的代码带有type = "text"
。用纯文本制作下标字符将很困难。
如果将输出设置为html
,则只需使用stringr::str_replace()
在HTML中插入下标:<sub> <\sub>
。
对于一个可复制的示例,让我们使用mtcars
:
想象一下,我们要使表中的“观察”最后一个字母下标。
library(stargazer) library(tidyverse) fit1 <- lm(mpg ~ cyl, data = mtcars) output <- stargazer(fit1, type = "HTML") # gives you output # replace output with the subscripted html output <- str_replace(output, "Observations", "Observation<sub>s</sub>") write_lines(output, "subscript_example.html")
给出所需的下标,如下所示:
最后,我读到最好用xml2
而不是str_replace()
编辑HTML。也许其他人可以帮助您。上面的解决方案确实对我有用。