簡體   English   中英

如何抑制輸出文件中的stargazer()信息

[英]How to suppress stargazer() information in output file

我正在使用stargazer包輸出R數據幀作為乳膠代碼:

library(stargazer)

stargazer(mtcars)

這是輸出

% Table created by StarGazer v.3.0.1 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Thu, May 09, 2013 - 16:14:28
\begin{table}[htb] \centering 
  \caption{} 
  \label{} 
\footnotesize 

\begin{tabular}{@{\extracolsep{5pt}}l c c c c c } 
\\[-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] 
mpg & 32 & 20.091 & 6.027 & 10.400 & 33.900 \\ 
cyl & 32 & 6.188 & 1.786 & 4 & 8 \\ 
disp & 32 & 230.722 & 123.939 & 71.100 & 472.000 \\ 
hp & 32 & 146.688 & 68.563 & 52 & 335 \\ 
drat & 32 & 3.597 & 0.535 & 2.760 & 4.930 \\ 
wt & 32 & 3.217 & 0.978 & 1.513 & 5.424 \\ 
qsec & 32 & 17.849 & 1.787 & 14.500 & 22.900 \\ 
vs & 32 & 0.438 & 0.504 & 0 & 1 \\ 
am & 32 & 0.406 & 0.499 & 0 & 1 \\ 
gear & 32 & 3.688 & 0.738 & 3 & 5 \\ 
carb & 32 & 2.812 & 1.615 & 1 & 8 \\ 
\hline \\[-1.8ex] 
\normalsize 
\end{tabular} 
\end{table} 

請注意,輸出包括兩行乳膠注釋(前兩行,開頭%)。 如何停止輸出前兩行(開頭%)?

一個類似的問題,但有關xtable()的問題在這里被問到: 在R markdown文件上使用表格標題使用knitr在pandoc中使用轉換為pdf

從版本4.0開始(現在可在CRAN上使用),您可以使用參數header = FALSE運行stargazer,以省略Latex代碼輸出中的初始注釋。

可以直接修改輸出

mod_stargazer <- function(...){
  output <- capture.output(stargazer(...))
  # The first three lines are the ones we want to remove...
  output <- output[4:length(output)]
  # cat out the results - this is essentially just what stargazer does too
  cat(paste(output, collapse = "\n"), "\n")
}

這使

> mod_stargazer(mtcars)
\begin{table}[htb] \centering 
  \caption{} 
  \label{} 
\footnotesize 

\begin{tabular}{@{\extracolsep{5pt}}l c c c c c } 
\\[-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] 
mpg & 32 & 20.091 & 6.027 & 10.400 & 33.900 \\ 
cyl & 32 & 6.188 & 1.786 & 4 & 8 \\ 
disp & 32 & 230.722 & 123.939 & 71.100 & 472.000 \\ 
hp & 32 & 146.688 & 68.563 & 52 & 335 \\ 
drat & 32 & 3.597 & 0.535 & 2.760 & 4.930 \\ 
wt & 32 & 3.217 & 0.978 & 1.513 & 5.424 \\ 
qsec & 32 & 17.849 & 1.787 & 14.500 & 22.900 \\ 
vs & 32 & 0.438 & 0.504 & 0 & 1 \\ 
am & 32 & 0.406 & 0.499 & 0 & 1 \\ 
gear & 32 & 3.688 & 0.738 & 3 & 5 \\ 
carb & 32 & 2.812 & 1.615 & 1 & 8 \\ 
\hline \\[-1.8ex] 
\normalsize 
\end{tabular} 
\end{table}  

暫無
暫無

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

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