Stargazer R包装:标题在乳胶表中的位置
我使用r中的stargazer Package生成胶乳文档的汇总统计信息。 但是,该函数会在表格顶部生成标题(标题)的乳胶代码。 是否有简单的方法把标题放在桌子下面?
require(stargazer)
df <- data.frame(a=c(1,2,3),
b=c(2,3,5),
c=c(8,8,9))
stargazer(df,summary = TRUE, type = "latex",
title = "summary statistic")
该函数的输出如下所示:
begin{table}[!htbp] centering
caption{summary statistic}
label{}
begin{tabular}{@{extracolsep{5pt}}lccccc}
[-1.8ex]hline
hline [-1.8ex]
Statistic & multicolumn{1}{c}{N} & multicolumn{1}{c}{Mean} & multicolumn{1}{c}{St. Dev.} & multicolumn{1}{c}{Min} & multicolumn{1}{c}{Max}
hline [-1.8ex]
a & 3 & 2.000 & 1.000 & 1 & 3
b & 3 & 3.333 & 1.528 & 2 & 5
c & 3 & 8.333 & 0.577 & 8 & 9
hline [-1.8ex]
end{tabular}
end{table}
请注意,标题位于表格的顶部。 我想要的是以下内容:
begin{table}[!htbp] centering
begin{tabular}{@{extracolsep{5pt}}lccccc}
[-1.8ex]hline
hline [-1.8ex]
Statistic & multicolumn{1}{c}{N} & multicolumn{1}{c}{Mean} & multicolumn{1}{c}{St. Dev.} & multicolumn{1}{c}{Min} & multicolumn{1}{c}{Max}
hline [-1.8ex]
a & 3 & 2.000 & 1.000 & 1 & 3
b & 3 & 3.333 & 1.528 & 2 & 5
c & 3 & 8.333 & 0.577 & 8 & 9
hline [-1.8ex]
end{tabular}
caption{summary statistic}
label{}
end{table}
HTH Andreas
我想做同样的事情,来找到答案。 既然没有现成的答案,这是我的方法。 基本思想是编写一个捕获和重新创建观stargazer
输出的函数,将标题和标签移动到底部:
caption_at_bottom <- function(expr) {
x <- capture.output(expr)
cap <- grep("\caption", x)
lab <- grep("\label", x)
last <- grep("\end{table", x)
cat(
paste(
c(x[-last], x[cap], x[lab], x[last])[-c(cap, lab)]
, collapse = "n")
, "n")
}
使用你的例子:
caption_at_bottom(
stargazer(df, summary = TRUE, type = "latex", header = F,
title = "summary statistic")
)
# begin{table}[!htbp] centering
# begin{tabular}{@{extracolsep{5pt}}lccccc}
# [-1.8ex]hline
# hline [-1.8ex]
# Statistic & multicolumn{1}{c}{N} & multicolumn{1}{c}{Mean} & multicolumn{1}{c}{St. Dev.} & multicolumn{1}{c}{Min} & multicolumn{1}{c}{Max}
# hline [-1.8ex]
# a & 3 & 2.000 & 1.000 & 1 & 3
# b & 3 & 3.333 & 1.528 & 2 & 5
# c & 3 & 8.333 & 0.577 & 8 & 9
# hline [-1.8ex]
# end{tabular}
# caption{summary statistic}
# label{}
# end{table}
你想改变调用stargazer()
的note
参数
stargazer(df,summary = TRUE, type = "latex",
title = "summary statistic",
notes = "put your summary statistic note here"
)
链接地址: http://www.djcxy.com/p/25005.html