r - Row Percentages in crosstable generated from summary() from the Hmisc package -
i have been trying learn use summary()-function hmisc-package generate crosstables include chisquared tests. board i'm there. can't figure out how obtain row-percentages instead of column percentages.
#data: v1 <- sample(letters[8:12],200,replace=true) v2 <- sample(letters[1:2],200,replace=true) month <- sample(month.name[7:9],200,replace=true) df <- data.frame(v1,v2,month) #table: latex( summary( month ~ v1 + v2 , data=df, method="reverse" ,test=true), exclude1=false,file="",booktabs=true,long=true) which gets me this: 
this gets me column-percentages. looking way turn around row-percentages instead. i've been searching hmisc-documentation "row" , "column" , "percent" no luck. summary.formular() function has optional argument "fun" on head row percentages...
please help
if hack around bit hmisc::formatcats. namely, change margin 2 1. can there.
part of formatcats
denom <- if (type == 1) apply(tab, 2, sum) else group.freq pct <- 100 * (if (ncol(tab) > 1) sweep(tab, 2, denom, fun = "/") else tab/denom) change to
denom <- if (type == 1) apply(tab, 1, sum) else group.freq pct <- 100 * (if (ncol(tab) > 1) sweep(tab, 1, denom, fun = "/") else tab/denom) i made gist @ https://gist.github.com/jwijffels/5599349 modified function called myformatcats. it, assign in hmisc namespace override hmisc::formatcats , prints out col pct.
require(hmisc) require(devtools) source_gist("5599349") assigninnamespace(x="formatcats", value=myformatcats, ns="hmisc") v1 <- sample(letters[8:12],200,replace=true) v2 <- sample(letters[1:2],200,replace=true) month <- sample(month.name[7:9],200,replace=true) df <- data.frame(v1,v2,month) summary( month ~ v1 + v2 , data=df, method="reverse")
Comments
Post a Comment