R - contingency table (addmargins() and prop.table())

21 Jan 2018

depsmok <- matrix(c(144,1729,50,1290),byrow=T,ncol=2);
dimnames(depsmok) <- list(Ever_Smoker=c("Yes","No"),Depression=c("Yes","No"));
depsmok
addmargins(depsmok)
addmargins(prop.table(depsmok))
sweep(depsmok,1,rowSums(depsmok), "/")
[ R  function  ]