我有一个data.frame,我正试图用天文望远镜将它转换成乳胶码:
habitats_df <- data.frame(habitat = c("beach", "grassland", "freshwater"), v1 = c(0.000, 0.670, 0.032), v2 = c(0.005, 0.824, 0.012))
library(stargazer)
stargazer(habitats_df, summary = F)
% Table created by stargazer v.4.5.3 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Wed, Jan 22, 2014 - 11:11:44
\begin{table}[!htbp] \centering
\caption{}
\label{}
\begin{tabular}{@{\extracolsep{5pt}} ccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
habitat & v1 & v2 \\
\hline \\[-1.8ex]
beach & $0$ & $0.005$ \\
grassland & $0.670$ & $0.824$ \\
freshwater & $0.032$ & $0.012$ \\
\hline \\[-1.8ex]
\normalsize
\end{tabular}
\end{table} 注:天文望远镜以数学方式打印表格,因此它用$作为数字的附件。我怎样才能阻止凝视者在乳胶数学模式下打印桌子呢?
发布于 2014-01-22 18:27:12
将不希望作为数字的任何数字列转换为字符:
habitats_df$v1 <- as.character(habitats_df$v1)
> stargazer(habitats_df, summary = F)
% Table created by stargazer v.4.5.3 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Wed, Jan 22, 2014 - 11:23:59
\begin{table}[!htbp] \centering
\caption{}
\label{}
\begin{tabular}{@{\extracolsep{5pt}} ccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
habitat & v1 & v2 \\
\hline \\[-1.8ex]
beach & 0 & $0.005$ \\
grassland & 0.67 & $0.824$ \\
freshwater & 0.032 & $0.012$ \\
\hline \\[-1.8ex]
\normalsize
\end{tabular}
\end{table} 至于“为什么”,这是因为,否则数字不能正确排字。如果您有负值,数学模式将使用较长的破折号,它将允许LaTeX控制打印的数字数。否则,如上文所示,如果要控制数字的数量,就必须使用R中的sprintf进行控制。
发布于 2014-01-24 08:29:37
latexSN做的很好。
habitats_df$v1 <- latexSN(habitats_df$v1)
habitats_df$v2 <- latexSN(habitats_df$v2)
library(stargazer)
stargazer(habitats_df, summary = F)
% Table created by stargazer v.4.5.3 by Marek Hlavac, Harvard University. E-mail: hlavac at fas.harvard.edu
% Date and time: Fri, Jan 24, 2014 - 08:32:39
\begin{table}[!htbp] \centering
\caption{}
\label{}
\begin{tabular}{@{\extracolsep{5pt}} ccc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
habitat & v1 & v2 \\
\hline \\[-1.8ex]
beach & 0.000 & 0.005 \\
grassland & 0.670 & 0.824 \\
freshwater & 0.032 & 0.012 \\
\hline \\[-1.8ex]
\normalsize
\end{tabular}
\end{table}https://stackoverflow.com/questions/21281207
复制相似问题