簡體   English   中英

嵌套乳膠表與觀星者

[英]Nested latex table with stargazer

我有一個這樣的數據幀列表:

library(plyr)
mt_list <- dlply(mtcars, .(cyl), data.frame)
names(mt_list) <- c("four", "six", "eight")

我想使用stargazer包創建一個嵌套的乳膠表。 通過嵌套,我的意思是我想在一個表中組合三個數據幀,並在表中為每個三個數據幀提供自己的標題。 乳膠表應該看起來這個(photoshopped圖像):

在此輸入圖像描述

是否可以在R中創建一個看起來像這樣的表? 我特別感興趣的是使用stargazer包來做到這一點。

不完全是你想要的,但應該是一個良好的開端。

stargazer(mt_list,type='text',summary=FALSE,
          title=c('Six','Four','Eight'))
## 
## Six
## =========================================================
## mpg    cyl  disp   hp  drat   wt    qsec  vs am gear carb
## ---------------------------------------------------------
## 22.800  4    108   93  3.850 2.320 18.610 1  1   4    1  
## 24.400  4  146.700 62  3.690 3.190   20   1  0   4    2  
## 22.800  4  140.800 95  3.920 3.150 22.900 1  0   4    2  
## 32.400  4  78.700  66  4.080 2.200 19.470 1  1   4    1  
## 30.400  4  75.700  52  4.930 1.615 18.520 1  1   4    2  
## 33.900  4  71.100  65  4.220 1.835 19.900 1  1   4    1  
## 21.500  4  120.100 97  3.700 2.465 20.010 1  0   3    1  
## 27.300  4    79    66  4.080 1.935 18.900 1  1   4    1  
## 26      4  120.300 91  4.430 2.140 16.700 0  1   5    2  
## 30.400  4  95.100  113 3.770 1.513 16.900 1  1   5    2  
## 21.400  4    121   109 4.110 2.780 18.600 1  1   4    2  
## ---------------------------------------------------------
## 
## Four
## =========================================================
## mpg    cyl  disp   hp  drat   wt    qsec  vs am gear carb
## ---------------------------------------------------------
## 21      6    160   110 3.900 2.620 16.460 0  1   4    4  
## 21      6    160   110 3.900 2.875 17.020 0  1   4    4  
## 21.400  6    258   110 3.080 3.215 19.440 1  0   3    1  
## 18.100  6    225   105 2.760 3.460 20.220 1  0   3    1  
## 19.200  6  167.600 123 3.920 3.440 18.300 1  0   4    4  
## 17.800  6  167.600 123 3.920 3.440 18.900 1  0   4    4  
## 19.700  6    145   175 3.620 2.770 15.500 0  1   5    6  
## ---------------------------------------------------------
## 
## Eight
## =========================================================
## mpg    cyl  disp   hp  drat   wt    qsec  vs am gear carb
## ---------------------------------------------------------
## 18.700  8    360   175 3.150 3.440 17.020 0  0   3    2  
## 14.300  8    360   245 3.210 3.570 15.840 0  0   3    4  
## 16.400  8  275.800 180 3.070 4.070 17.400 0  0   3    3  
## 17.300  8  275.800 180 3.070 3.730 17.600 0  0   3    3  
## 15.200  8  275.800 180 3.070 3.780   18   0  0   3    3  
## 10.400  8    472   205 2.930 5.250 17.980 0  0   3    4  
## 10.400  8    460   215   3   5.424 17.820 0  0   3    4  
## 14.700  8    440   230 3.230 5.345 17.420 0  0   3    4  
## 15.500  8    318   150 2.760 3.520 16.870 0  0   3    2  
## 15.200  8    304   150 3.150 3.435 17.300 0  0   3    2  
## 13.300  8    350   245 3.730 3.840 15.410 0  0   3    4  
## 19.200  8    400   175 3.080 3.845 17.050 0  0   3    2  
## 15.800  8    351   264 4.220 3.170 14.500 0  1   5    4  
## 15      8    301   335 3.540 3.570 14.600 0  1   5    8  

## ---------------------------------------------------------

這只是@ agstudy解決方案正確性的證明。 如果yopu設置type =“latex”並創建帶有文檔類前導碼的tex文檔並放入TeX處理器,您將獲得:

\documentclass[a4paper,12pt]{article}
\begin{document}
% 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 03, 2014 - 11:25:30
\begin{table}[!htbp] \centering 
  \caption{Six} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}} ccccccccccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
mpg & cyl & disp & hp & drat & wt & qsec & vs & am & gear & carb \\ 
\hline \\[-1.8ex] 
$22.800$ & $4$ & $108$ & $93$ & $3.850$ & $2.320$ & $18.610$ & $1$ & $1$ & $4$ & $1$ \\ 
$24.400$ & $4$ & $146.700$ & $62$ & $3.690$ & $3.190$ & $20$ & $1$ & $0$ & $4$ & $2$ \\ 
snipped extraneous lines
$15.800$ & $8$ & $351$ & $264$ & $4.220$ & $3.170$ & $14.500$ & $0$ & $1$ & $5$ & $4$ \\ 
$15$ & $8$ & $301$ & $335$ & $3.540$ & $3.570$ & $14.600$ & $0$ & $1$ & $5$ & $8$ \\ 
\hline \\[-1.8ex] 
\normalsize 
\end{tabular} 
\end{table} 

\end{document}

為什么只有3個表中的兩個? 當我進行排版時,這產生了兩頁pdf,我不認為SO可以處理pdf,所以我轉換為tiff。 tiff輸出為16 MB,因此像tiff文件一樣上傳為圖像文件似乎有點荒謬。 Png格式無法處理多頁文件,因此只顯示了兩個表。 在此輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM