【问题标题】:Omit floating and document environments from stargazer regression table output从 stargazer 回归表输出中省略浮动和文档环境
【发布时间】:2014-01-16 11:07:29
【问题描述】:

我刚开始使用 stargazer 包在 R 中制作回归表,但不知道如何在没有浮动或文档环境的情况下将表输出写入 .tex 文件(以及序言在文档环境的情况下)。也就是说,我只想要表格环境。我的工作流程是将表格浮动环境以及相关的标题和标签保留在论文正文中,并使用\input{}链接到表格的表格环境。

这可能吗?

# bogus data
my.data <- data.frame(y = rnorm(10), x = rnorm(10))
my.lm <- lm(y ~ x, data=my.data)

# if I write to file, then I can omit the floating environment,
# but not the document environment
# (i.e., file contains `\documentclass{article}` etc.)
stargazer(my.lm, float=FALSE, out="option_one.tex")

# if I write to a text connection with `sink`,
# then I can omit both floating and document environments, 
# but not commands
# (i.e., log contains `sink` and `stargazer` commands)
con <- file("option_two.tex")
sink(con)
stargazer(my.lm, float=FALSE)
sink()

【问题讨论】:

    标签: r stargazer


    【解决方案1】:

    将您的观星结果保存到一个对象:

    res <- stargazer(my.lm, float=FALSE)
    

    如果您查看res 的内容,您会发现它只是一系列文本行。像这样使用cat() 将其写入文件

    cat(res, file="tab_results.tex", sep="\n")
    

    sep="\n" 是必需的,因为 res 对象中的文本行本身不包含任何换行符。如果我们保留使用默认的sep=" ",那么您的表格将作为一长行写入 tex 文件。

    希望这会有所帮助。

    【讨论】:

    • 不错。感谢有关对象的课程。
    猜你喜欢
    • 2016-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    • 2022-08-14
    • 1970-01-01
    相关资源
    最近更新 更多