inst/examples/Ex2way.r

### Contrived example looking at, e.g., the distribution of A-K-Q card counts
### in two partners' Bridge hands


hand1=rhyper(1000,12,40,13)
hand2=rhyper(1000,12-hand1,27+hand1,13)
handNames=c("0-1",2:4,"5 or more")


### The problem is ridiculously symmetric, so I de-symmetrize the presentation slightly:

book3<-XLwriteOpen("hands.xls") 
XLtwoWay(book3,"PartnersAKQcounts",cut(hand1,c(0,2:6,14)-0.5),cut(hand2,c(0,2:5,14)-0.5),
         rowTitle="AKQ's in Hand 1 (rows) vs. Hand 2",
         rowNames=c(handNames[-5],5,"6 or more","Total"),
         colNames=c(handNames,"Total"),header=TRUE)

## Same table, but percents now condition on columns rather than rows, 
## counts/pct header row removed - but a title added.
## Also, Chi-square p-value now placed below the table rather than the default top-right corner
XLtwoWay(book3,"PartnersAKQcounts",cut(hand1,c(0,2:6,14)-0.5),cut(hand2,c(0,2:5,14)-0.5),
         rowTitle="AKQ's in Hand 1 (rows) vs. Hand 2",
         rowNames=c(handNames[-5],5,"6 or more","Total"),
         colNames=c(handNames,"Total"),header=FALSE,row1=12,sumby=2,
         title="Now Percents are Summed by Column:",testBelow=TRUE)

cat("Look for",paste(getwd(),"hands.xls",sep='/'),"to see the results!\n")

Try the table1xls package in your browser

Any scripts or data that you put into this service are public.

table1xls documentation built on May 2, 2019, 5:54 a.m.