在 R 的 stargazer 表中格式化注释 [英] Formatting notes in R's stargazer tables
问题描述
我正在使用 stargazer
包来生成(回归输出)表.在我开始编辑笔记之前,一切都在创造奇迹.首先:换行很难,但 Bryan
通过改变原来的LaTeX
代码产生:
extit{注:} &multicolumn{4}{l}{逻辑回归.因变量:一个指示变量...以及一些非常长且有趣的评论.} \
到
multicolumn{5}{l} {parbox[t]{11cm}{ extit{Notes:} 逻辑回归.因变量:一个指示变量 ... AND 一些非常长且有趣的评论.}} \
手工编辑既费时又容易出错.所以我正在寻找一种从 R
解决这个问题的方法,我目前正在使用以下方法:
stargazer([...],样式 = qje",notes.append = FALSE,notes.align = l",notes = "\parbox[t]{7cm}{Logistic 回归.因变量:指标变量...以及一些非常长且有趣的评论.}")
stargazer 不可见地将其输出作为字符向量返回,特别是您可以对其进行后期处理.根据您要更改的内容,这可能涉及一些正则表达式.或者,在这种情况下,如果您知道注释行应该是什么样子,您可以简单地将错误的行替换为您想要的.这是一个最小的可重现示例:
df <- data.frame(x = 1:10 + rnorm(100),y = 1:10 + rnorm(100))reg <- lm(y ~ x, 数据 = df)明星 <- 观星者(注册,样式 = qje",notes.append = FALSE,notes.align = l",notes = "这将被替换")note.latex <- "\multicolumn{5}{l} {\parbox[t]{11cm}{ \textit{Notes:} 逻辑回归.因变量:指示变量 ... AND 一些很长和有趣的评论.}} \\"star[grepl("Note",star)] <- note.latex猫 (星, sep = "
")
I am using stargazer
package to produce (regression output) tables. Everything working miracles until I start editing the notes. First: line breaks are hard, but Bryan suggests a manual solution that is not elegant, but works. Second I need to make it start from the very left of the table.
Here is an example of the notes I am trying to produce from within R
.
Produced by changing the original LaTeX
code from:
extit{Note:} & multicolumn{4}{l}{Logistic regression. Dependent variable: an indicator varible ... AND Some very long and interesting comment.} \
To
multicolumn{5}{l} {parbox[t]{11cm}{ extit{Notes:} Logistic regression. Dependent variable: an indicator varible ... AND Some very long and interesting comment.}} \
Editing by hand is time-consuming and error-prone. So I am looking for a way to solve this from R
, where I am currently using the following:
stargazer([...],
style = "qje", notes.append = FALSE, notes.align = "l",
notes = "\parbox[t]{7cm}{Logistic regression. Dependent variable: an indicator
varible ... AND Some very long and interesting comment.}")
stargazer returns its output invisibly as a character vector, specifically so you can post-process it. Depending what you want to change, this may involve some regex. Or, as in this case, if you know what your notes line should look like, you can simply replace the wrong line with what you want. Here's a minimal reproducible example:
df <- data.frame(x = 1:10 + rnorm(100),
y = 1:10 + rnorm(100))
reg <- lm(y ~ x, data = df)
star <- stargazer(reg,
style = "qje", notes.append = FALSE, notes.align = "l",
notes = "This will be replaced")
note.latex <- "\multicolumn{5}{l} {\parbox[t]{11cm}{ \textit{Notes:} Logistic regression. Dependent variable: an indicator varible ... AND Some very long and interesting comment.}} \\"
star[grepl("Note",star)] <- note.latex
cat (star, sep = "
")
这篇关于在 R 的 stargazer 表中格式化注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!