在R的观星台中格式化笔记 [英] Formatting notes in R's stargazer tables

查看:65
本文介绍了在R的观星台中格式化笔记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 stargazer 包来生成(回归输出)表.在我开始编辑笔记之前,所有事情都是奇迹.第一:换行很难,但Bryan

通过更改以下原始 LaTeX 代码生成:

\textit{注意:} &\ multicolumn {4} {l} {逻辑回归.因变量:变量变量...并且有一些非常长且有趣的注释.} \\ 

收件人

  \ multicolumn {5} {l} {\ parbox [t] {11cm} {\ textit {注意:} Logistic回归.因变量:指标变量...并且有一些非常长且有趣的注释.}} \\ 

手工编辑既费时又容易出错.因此,我正在寻找一种方法来解决 R 的问题,目前我正在使用以下方法:

  stargazer([...],style ="qje",notes.append = FALSE,notes.align ="l",notes ="\\ parbox [t] {7cm} {逻辑回归.因变量:一个指标易变……还有一些很长很有趣的评论.}) 

解决方案

stargazer不可见地将其输出作为字符向量返回,因此可以对其进行后处理.根据您要更改的内容,这可能涉及一些正则表达式.或者,在这种情况下,如果您知道便笺行应为什么样,则只需将错误的行替换为所需的行即可.这是一个最小的可重现示例:

  df<-data.frame(x = 1:10 + rnorm(100),y = 1:10 + rmrm(100))reg<-lm(y〜x,data = df)星<-观星者(reg,style ="qje",notes.append = FALSE,notes.align ="l",notes =将被替换")note.latex<-"\\ multicolumn {5} {l} {\\ parbox [t] {11cm} {\\ t​​extit {Notes:} Logistic回归.因变量:指示变量... AND有些很长和有趣的评论.}} \\\\star [grepl("Note",star)]<-note.latex猫(星号,sep ="\ n") 

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:

\textit{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}{ \textit{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 = "\n")

这篇关于在R的观星台中格式化笔记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆