> pdf("C:\\Rmisc\\coldfish.pdf") > > coldfish <- read.fwf("C:\\data\\coldfish.dat", width=c(8,8), + col.names=c("species","injury")) > > attach(coldfish) > > species <- factor(species,levels=1:3, + labels=c("tropical","subtropical","temperate")) > > injury <- factor(injury,levels=1:3, + labels=c("seldom","often","always")) > > sp.in.table <- table(species,injury) > sp.in.table # prints out contingency table injury species seldom often always tropical 0 3 14 subtropical 1 5 5 temperate 4 2 0 > > prop.table(sp.in.table,1) # Proportions of injuries by species injury species seldom often always tropical 0.0000000 0.1764706 0.8235294 subtropical 0.0909091 0.4545455 0.4545455 temperate 0.6666667 0.3333333 0.0000000 > prop.table(sp.in.table,2) # Proportions of species by injury injury species seldom often always tropical 0.0000000 0.3000000 0.7368421 subtropical 0.2000000 0.5000000 0.2631579 temperate 0.8000000 0.2000000 0.0000000 > sp.in.table/sum(sp.in.table) # Overall Proportions across table injury species seldom often always tropical 0.00000000 0.08823529 0.41176471 subtropical 0.02941176 0.14705882 0.14705882 temperate 0.11764706 0.05882353 0.00000000 > > par(mfrow=c(2,2)) > barplot(sp.in.table) > barplot(t(sp.in.table)) > barplot(sp.in.table,beside=T) > barplot(t(sp.in.table),beside=T) > > > dev.off() null device 1 >