我已经使用group_by运算符来创建摘要概述。我该如何将它们导出到乳胶中?
> ## DT & Gender/Campus/SE_track/programme
> group_by(starters, starters$SE_track) %>%
+ summarise(
+ count = n(),
+ mean = mean(Total_testscore, na.rm = TRUE),
+ sd = sd(Total_testscore, na.rm = TRUE))
# A tibble: 3 x 4
`starters$SE_track` count mean sd
<fct> <int> <dbl> <dbl>
1 ASO 207 9.75 2.85
2 KSO 39 8.90 3.03
3 TSO 40 8.98 2.83
答案 0 :(得分:1)
通过使用 xtable 库,您将直接获得一个输出,可以将其复制/粘贴到Latex中。
library(xtable)
data("tli")
xtable(tli[1:10,])
#\begin{table}[ht]
#\centering
#\begin{tabular}{rrlllr}
#\hline
# & grade & sex & disadvg & ethnicty & tlimth \\
#\hline
#1 & 6 & M & YES & HISPANIC & 43 \\
#2 & 7 & M & NO & BLACK & 88 \\
#3 & 5 & F & YES & HISPANIC & 34 \\
#4 & 3 & M & YES & HISPANIC & 65 \\
#5 & 8 & M & YES & WHITE & 75 \\
#6 & 5 & M & NO & BLACK & 74 \\
#7 & 8 & F & YES & HISPANIC & 72 \\
#8 & 4 & M & YES & BLACK & 79 \\
#9 & 6 & M & NO & WHITE & 88 \\
#10 & 7 & M & YES & HISPANIC & 87 \\
#\hline
#\end{tabular}
#\end{table}
您当然也可以在管道中的 group_by 之后执行此操作。我在这里使用mtcars数据集。
mtcars %>%
group_by(mpg) %>%
summarise(meanD= mean(disp), meanH=mean(hp)) %>%
xtable()