簡體   English   中英

從stargazer回歸表輸出中忽略浮動和文檔環境

[英]Omit floating and document environments from stargazer regression table output

我剛剛開始使用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()

將觀星結果保存到對象:

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

如果您查看res的內容,那么您會看到它只是一系列文本行。 像這樣使用cat()將其寫入文件

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

只需要使用sep="\\n"因為res對象中的文本行本身不包含任何換行符。 如果我們使用默認的sep=" "離開,那么您的表將作為一長行寫入tex文件。

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM