R - transform output format of dplyr summarise -


i appreciate using summarise dyplr produce summary statistics.

however, not totally convinced "format" of ouput.

for example :

mt = mtcars %>%   group_by(gear, vs) %>%   summarise(mean (disp) )  

will produce

  gear vs mean(disp) 1    3  0   357.6167 2    3  1   201.0333 3    4  0   160.0000 4    4  1   115.6200 5    5  0   229.3250 6    5  1    95.1000 

for scientific reports, rather prefer display output (whatever statistical meaning of mtcars example) :

  gear mean vs = 1 mean vs = 0     3    201.0333    357.6167     4    115.6200    160.0000     5     95.1000    229.3250 

do know if possible "control" output format of dplyr summarise ?

you use spread tidyr extend pipeline. note, assigned name mean referenced within spread call.

library(dplyr) library(tidyr)  mtcars %>%      group_by(gear, vs) %>%      summarise(mean_disp = mean (disp) ) %>%     spread(vs, mean_disp)  source: local data frame [3 x 3]    gear        0        1 1    3 357.6167 201.0333 2    4 160.0000 115.6200 3    5 229.3250  95.1000 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -