How to print (to paper) a nicely-formatted data frame

后端 未结 10 2077
深忆病人
深忆病人 2020-12-07 08:41

I\'d like to print nicely-formatted data frames to paper, ideally from within a script. (I am trying to collect data using an instrument and automatically process and print

10条回答
  •  长情又很酷
    2020-12-07 09:06

    Surprised nobody has mentioned the stargazer package for nice printing of data.

    You can output a nice-looking text file:

    stargazer(mtcars, type = 'text', out = 'out.txt')
    
    ============================================
    Statistic N   Mean   St. Dev.  Min     Max  
    --------------------------------------------
    mpg       32 20.091   6.027   10.400 33.900 
    cyl       32  6.188   1.786     4       8   
    disp      32 230.722 123.939  71.100 472.000
    hp        32 146.688  68.563    52     335  
    drat      32  3.597   0.535   2.760   4.930 
    wt        32  3.217   0.978   1.513   5.424 
    qsec      32 17.849   1.787   14.500 22.900 
    vs        32  0.438   0.504     0       1   
    am        32  0.406   0.499     0       1   
    gear      32  3.688   0.738     3       5   
    carb      32  2.812   1.615     1       8   
    --------------------------------------------
    

    Or even HTML:

    stargazer(mtcars, type = 'html', out = 'out.html')
    

    StatisticNMeanSt. Dev.MinMax
    mpg3220.0916.02710.40033.900
    cyl326.1881.78648
    disp32230.722123.93971.100472.000
    hp32146.68868.56352335
    drat323.5970.5352.7604.930
    wt323.2170.9781.5135.424
    qsec3217.8491.78714.50022.900
    vs320.4380.50401
    am320.4060.49901
    gear323.6880.73835
    carb322.8121.61518

提交回复
热议问题