【发布时间】:2014-02-05 17:15:51
【问题描述】:
xtable 默认从回归输出中删除 NA 值。我想强制这些系数显示在输出中,以及它们的NA 值。 NA.string 到 print.xtable 有一个参数,我认为它会提供此功能,但它至少对 lm 对象没有任何作用。
例如,
df <- data.frame(A=1:3, B=2:4, C=2:4)
reg <- lm(A ~ B + C, df)
print(xtable(reg), NA.string = "Foo")
创建以下输出
% latex table generated in R 3.0.2 by xtable 1.7-1 package
% Wed Feb 5 11:04:09 2014
\begin{table}[ht]
\centering
\begin{tabular}{rrrrr}
\hline
& Estimate & Std. Error & t value & Pr($>$$|$t$|$) \\
\hline
(Intercept) & -1.0000 & 0.0000 & -Inf & 0.0000 \\
B & 1.0000 & 0.0000 & Inf & 0.0000 \\
\hline
\end{tabular}
\end{table}
而我想要输出的是
% latex table generated in R 3.0.2 by xtable 1.7-1 package
% Wed Feb 5 11:04:09 2014
\begin{table}[ht]
\centering
\begin{tabular}{rrrrr}
\hline
& Estimate & Std. Error & t value & Pr($>$$|$t$|$) \\
\hline
(Intercept) & -1.0000 & 0.0000 & -Inf & 0.0000 \\
B & 1.0000 & 0.0000 & Inf & 0.0000 \\
C & NA & NA & NA & NA \\ %%% This is the new line
\hline
\end{tabular}
\end{table}
【问题讨论】:
-
我没用过
xtable,所以猜测。也许看看xtable(reg)的结构,看看你是否可以操纵它来添加一个值“NA”的元素C,类似于现有的任何包含“B”的东西。 -
如果您查看 summary(reg)$coefficients 您会看到这是打印的表格,它不包括 C 行;然而 print(summary(reg)) 显示 NA 行。
-
我宁愿不直接编辑
xtable对象。