Enhance the output of XTab
Source: https://stackoverflow.com/questions/31544726/how-to-create-frequency-tables-with-xtabs
enhanceXTabs <- function(aXTab, aToExcel = FALSE){
## PURPOSE: print an xtab with percentages
## SOURCE: https://stackoverflow.com/questions/31544726/how-to-create-frequency-tables-with-xtabs
xtab.margin <-addmargins(aXTab)
xtab.prop <- addmargins(prop.table(aXTab))
ret <-sprintf('%s (%6.2f%%)',
format(xtab.margin, big.mark=','),
100*xtab.prop)
attributes(ret)<-attributes(xtab.margin)
print(quote=FALSE, na.print='NA', ret)
if(aToExcel){
ss_send2excel(ret)
}
}
No comments:
Post a Comment