问题
I am currently using xtable to generate Latex tables from R. It works fine, but in one of the tables I have significance stars to some of the numbers. Something like this dataframe X:
1 2 3 4 5 Test1 Test2 Test3
a "1.34" "0.43" "-0.26" "0.13" "0.05" "3.35^{.}" "343^{***}" "3244^{***}"
b "2.02" "2.17" "-3.19" "4.43" "1.43" "390.1^{***}" "31.23^{***}" "24^{***}"
c "23.07" "32.1" "24.3" "3.89" "0.4" "429.38^{***}" "17.04^{***}" "2424^{***}"
d "21.48" "14.45" "14.19" "22.04" "0.15" "385.17^{***}" "2424^{***}" "2424^{***}"
I am using '^' before the stars because in Latex significance stars look better in that format. The other option would be:
a "1.34" "0.43" "-0.26" "0.13" "0.05" "3.35." "343***" "3244***"
b "2.02" "2.17" "-3.19" "4.43" "1.43" "390.1***" "31.23^***" "24***"
# etc.
If I use xtable via:
print(xtable(X, label="X"),
size="normalsize",
include.rownames=FALSE,
include.colnames=TRUE,
caption.placement="top",
hline.after=NULL
)
I get an output like the following:
\begin{table}[ht]
\centering
{\normalsize
\begin{tabular}{llllllll}
1 & 2 & 3 & 4 & 5 & Test1 & Test2 & Test3 \\
242 & 123 & -42.3 & 0.43 & 34 & 3.35\verb|^|\{.\} # Hhere is the problem: \verb
& 242.58\verb|^|\{***\} & 0.06\verb|^|\{***\} \\ # etc. etc.
\end{tabular}
}
\end{table}
The problem here is the \verb which was added. If xtable didn't add it, the table would be fine for me. So my question is: Is there a way around that? I just want significane stars which are in the format:
^{***}
in the Latex table, but produced in R already, so I can quickly produce new tables in the right format. Right now I am using the following function to create the stars, then I use 'paste' in a different function (not shown) to add them to the tests in the respective cases:
symnum(s[[p]], corr = FALSE, cutpoints = c(0, .001,.01,.05, .1, 1),
symbols = c("^{***}","^{**}","^{*}","^{.}"," "))
But maybe there is a better solution. Let me know.
回答1:
Try setting sanitize.text.function = function(x) x
to turn off the sanitizing of non-numeric values.
However, I would also recommend not using stars at all.
来源:https://stackoverflow.com/questions/20250057/use-xtable-to-produce-a-latex-table-with-significance-stars