dplyr pivot table
I want to obtain a pivot table with descending value. library(dplyr) library(tidyr) h<-mtcars %>% group_by(cyl, gear) %>% tally() %>% spread(gear, n, fill = 0) h<-h%>% add_rownames("index") i<-mtcars %>% group_by(cyl, gear) %>% tally() %>% spread(cyl, n, fill = 0) To obtain the sum of the values j<-i%>% select(-1)%>% summarise_each(funs(sum)) k<-t(j) k<- as.data.frame(k) k<-tbl_df(k) k<-k%>%add_rownames("index") l<-left_join(h,k,by="index") l<-l%>% select(-1)%>% arrange(desc(V1)) Is there another way to do the same in dplyr? We group by 'cyl', 'gear', get the frequency count ( tally() ),