通过R中的输出将组导出到latex

问题描述 投票:0回答:1

我使用了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
r export latex plyr
1个回答
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()
© www.soinside.com 2019 - 2024. All rights reserved.