Description Usage Arguments Details Value Author(s) See Also Examples
Calculates univariate summary statistics (optionally stratified), exports the formatted output to a spreadsheet, and saves the file.
1 2 3 4 5 6 | XLunivariate(wb, sheet, calcvar, colvar = rep("", length(calcvar)),
table1mode = FALSE, fun1 = list(fun = roundmean, name = "Mean"),
fun2 = list(fun = roundSD, name = "SD"), seps = c("", " (", ")"),
sideBySide = FALSE, title = NULL, rowTitle = "", rowNames = NULL,
colNames = rowNames, ord = NULL, row1 = 1, col1 = 1, purge = FALSE,
...)
|
wb |
a |
sheet |
numeric or character: a worksheet name (character) or position (numeric) within |
calcvar |
vector: variable to calculate the statistics for (usually numeric, can be logical). |
colvar |
vector: categorical variable to stratify |
table1mode |
logical: is the function called from |
fun1, fun2 |
two lists describing the utility functions that will calculate the statistics. Each list has a |
seps |
character vector of length 3, specifying the formatted separators before the output of |
sideBySide |
logical: should output be arranged horizontally rather than vertically? Default |
title |
character: an optional overall title to the table. Default ( |
rowTitle |
character: the title to be placed above the row name column (default empty string) |
rowNames |
character vector of row names. Default behavior ( |
colNames |
column names for stratifying variable, used when |
ord |
numeric vector specifying row-index order (i.e., a re-ordering of |
row1, col1 |
numeric: the first row and column occupied by the table (title included if relevant). |
purge |
logical: should |
... |
parameters passed on to |
This function evaluates up to 2 univariate functions on the input vector calcvar
, either as a single sample, or grouped by strata defined via colvar
(which is named this way for compatibility with XLtable1
). It produces a single-column or single-row table (apart from row/column headers), with each interior cell containing the formatted results from the two functions. The table is exported to a spreadsheet and the file is saved.
The cell can be formatted to show a combined result, e.g. "Mean (SD)" which is the default. Tne function is quite mutable: both fun1$fun, fun2$fun
and the strings separating their formatted output can be user-defined. The functions can return either a string (i.e., a formatted output) or a number that will be interpreted as a string in subsequent formatting.
The default calls roundmean,roundSD
and prints the summaries in "mean(SD)"
format.
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>
Uses writeWorksheet
to access the spreadsheet, rangeString
for some utilities that can be used as fun1$fun,fun2$fun
. For one-way (univariate) contingency tables, XLoneWay
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | book2<-XLwriteOpen("chick2.xls")
## Plain-vanilla
XLunivariate(book2,"weightByDiet",ChickWeight$weight,ChickWeight$Diet,
title="Mean Weights by Diet",rowTitle="Diet")
## Replace mean/SD with median/range, put results beside previous
XLunivariate(book2,"weightByDiet",ChickWeight$weight,ChickWeight$Diet,
title="Median Weights by Diet",rowTitle="Diet",col1=8,
fun1=list(fun=roundmedian,name="Median"),fun2=list(fun=rangeString,name="range"))
### You can also do only one statistic... by "killing" one of the functions
XLunivariate(book2,"weightByAge",ChickWeight$weight,ChickWeight$Time,
title="Mean Weights by Age",rowTitle="Age (Days)",seps=rep("",3),
fun2=list(fun=emptee,name=""))
cat("Look for",paste(getwd(),"chick2.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.