Description Usage Arguments Details Value Author(s) See Also Examples
Formats and exports a series of shared-structure tables, and saves the file.
1 2 3 |
wb |
a |
sheet |
numeric or character: a worksheet name (character) or position (numeric) within |
DF |
a rectangular array with all variables to be tabulated. |
colvar |
vector; specifies the variable to cross-tabulate for |
fun |
The |
title |
character: an optional overall title to the table. Default |
colTitle |
character: the title to be placed above the first column of the column variable. Default |
colNames |
character: when relevant, more descriptive names for columns in case |
row1, col1 |
numeric: the first row and column occupied by the table (title included if relevant). |
digits |
numeric: how many digits (after the decimal point) to show in the percents? Defaults to 1 if n>=500 or if using |
useNA |
How to handle missing values. Passed on to |
... |
additional arguments as needed, to pass on to |
purge |
logical should |
Auto-generation of a series of tables of the same type for a single dataset. One-way and two-way contingency tables and numerical summaries are all supported, but all summaries call the same atomic fun
.
The function employs convenience conventions for two-way tabulation: first, if colvar
is specified and fun
is left blank, then fun
will be set to XLtwoWay
. Second, if fun=XLtwoWay
and colvar
is left blank, then colvar
will be set to the last column of DF
.
For numerical summaries, use fun=XLunivariate
. If you specify colvar
, two-way summaries stratified by colvar
will be returned.
Note that this function does not mix and match. Just make several calls to XLtable1
with different sub-datasets and different values of fun
, and combine the results in your report document.
In a similar vein, two-way summaries do not return the marginal one-way summaries as a byproduct. For example, if you use fun=XLtwoWay
, then in order to get column totals for the generated two-way output, you will need to call XLtable1
again on the same data, using the default fun=XLoneWay
.
See the XLtwoWay
help page, for behavior regarding new-sheet creation, overwriting, etc.
The function returns invisibly, after writing the data into sheet
and saving the file.
Assaf P. Oron <assaf.oron.at.seattlechildrens.org>
XLoneWay
,XLtwoWay
,XLunivariate
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | table1<-XLwriteOpen("table1.xls")
## A default, option-free call generates one-way tables
XLtable1(table1,'cars1',mtcars[,c(2,8:11)])
## You can prettify a bit, first by changing variable names
names(mtcars)[c(2,8:11)]=c("Cylinders","V/S","Auto/Manual","Gears","Carbureutors")
XLtable1(table1,'cars1',mtcars[,c(2,8:11)],
title="'mtcars': Summary of Categorical Variables",col1=4)
## Now two-way, generated implicitly by specifying 'colvar' (unless fun=XLunivariate)
XLtable1(table1,'cars2',mtcars[,8:11],colvar=mtcars$Cylinders,
title="Cylinders vs. categorical variables",colTitle="Cylinders")
## Finally, two-way numerical summaries for continuous variables
names(mtcars)[c(1,3:7)]=c('MPG','Engine Vol.','HP',"Axle Ratio","Weight","Quarter Mile")
XLtable1(table1,'carsContinuous',mtcars[,c(1,3:7)],fun=XLunivariate,colvar=mtcars$Cylinders,
title="Cylinders vs. continuous variables",colTitle="Cylinders")
cat("Look for",paste(getwd(),"table1.xls",sep='/'),"to see the results!\n")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.