【发布时间】:2016-10-30 04:05:38
【问题描述】:
我正在尝试使用 stargazer 包在乳胶中输出数据帧。我希望列名包含乳胶代码,但 stargazer 不允许在数据框名称中使用乳胶代码。我也尝试使用 column.labels 参数,但此参数仅用于回归表,而不用于输出数据帧。这是我尝试过的两种方法。都没有用。
第一种方法 - 尝试更改数据框中变量的名称
代码:
# Creating a data frame
df = data.frame(x = 1:5, y = 6:10)
# Changing names
names(df) = c("$X$", "$Y$\\textsuperscript{1}")
# Exporting
stargazer(df, summary = F,
notes = "\\textsuperscript{1} This is a note that was supposed to refer to $Y$.")
输出(显然 stargazer 无法识别 LaTeX 代码):
% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Sat, Oct 29, 2016 - 20:46:22
\begin{table}[!htbp] \centering
\caption{}
\label{}
\begin{tabular}{@{\extracolsep{5pt}} ccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
& \$X\$ & \$Y\$\textbackslash textsuperscript\{1\} \\
\hline \\[-1.8ex]
1 & $1$ & $6$ \\
2 & $2$ & $7$ \\
3 & $3$ & $8$ \\
4 & $4$ & $9$ \\
5 & $5$ & $10$ \\
\hline \\[-1.8ex]
\end{tabular}
\end{table}
第二种方法——尝试使用 column.labels 参数
代码:
# Creating a data frame
df = data.frame(x = 1:5, y = 6:10)
# Exporting
stargazer(df, summary = F,
column.labels = c("$X$", "$Y$\\textsuperscript{1}"),
notes = "\\textsuperscript{1} This is a note that was supposed to refer to $Y$.")
输出(stargazer 直接忽略该参数):
% Table created by stargazer v.5.2 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Sat, Oct 29, 2016 - 20:57:41
\begin{table}[!htbp] \centering
\caption{}
\label{}
\begin{tabular}{@{\extracolsep{5pt}} ccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
& x & y \\
\hline \\[-1.8ex]
1 & $1$ & $6$ \\
2 & $2$ & $7$ \\
3 & $3$ & $8$ \\
4 & $4$ & $9$ \\
5 & $5$ & $10$ \\
\hline \\[-1.8ex]
\multicolumn{3}{l}{\textsuperscript{1} This is a note that was supposed to refer to $Y$.} \\
\end{tabular}
\end{table}
【问题讨论】: