Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested latex table with stargazer

Tags:

r

stargazer

I have a list of dataframes like these:

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

I want to create a nested latex table using the stargazer package. By nested, I mean I want to combine three dataframes within a single table and give each of the three dataframe's their own title within the table. The latex table should look this (photoshopped image):

enter image description here

Is it possible to create a table that looks like this from within R? I'm specifically interested in using the stargazer package to do this.

like image 299
luciano Avatar asked Aug 13 '26 19:08

luciano


1 Answers

Not exactly what you are looking for but should be a good start.

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  

## ---------------------------------------------------------
like image 143
agstudy Avatar answered Aug 16 '26 20:08

agstudy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!