Learn R Programming

table1xls (version 0.4.0)

XLoneWay: One-way Contingency Tables exported to a spreadsheet

Description

Calculates a one-way contingency table in counts and percents, exports a formatted output to a spreadsheet, and saves the file.

Usage

XLoneWay(wb, sheet, rowvar, table1mode = FALSE, title = NULL,
  rowTitle = "Value", rowNames = NULL, colNames = NULL, ord = NULL,
  row1 = 1, col1 = 1, digits = ifelse(length(rowvar) >= 500, 1, 0),
  combine = TRUE, useNA = "ifany", testname = NULL, testBelow = FALSE,
  margins = TRUE, ..., purge = FALSE, pround = 3)

Arguments

wb
sheet

numeric or character: a worksheet name (character) or position (numeric) within wb.

rowvar

vector: the categorical variable (logical, numeric, character, factor, etc.) to be tabulated.

table1mode

logical: is the function called from XLtable1? If TRUE, some modifications will be made to the output. Default FALSE.

title

character: an optional overall title to the table. Default (NULL) is no title.

rowTitle

character: the title to be placed above the row name column (default empty string)

rowNames

character: vector of row names. Default behavior (NULL): automatically determined from data

colNames

dummy argument for compatibility with calls from XLtable1(). Otherwise ignored by function.

ord

numeric vector specifying row-index order in the produced table. Default (NULL) is no re-ordering.

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, 0 otherwise.

combine

logical: should counts and percents be combined to the popular "Count(percent)" format, or presented side-by-side? (default TRUE)

useNA

How to handle missing values. Passed on to table (see help on that function for options).

testname

string, the name of a function to run a significance test on the table. Default NULL (no test).

testBelow

logical, should test p-value be placed right below the table? Default FALSE, which places it next to the table's right edge, one row below the column headings

margins

logical: should margins with totals be returned? Default TRUE.

...

additional arguments as needed, to pass on to get(textfun); for example, the reference frequencies for a Chi-Squared GoF test.

purge

logical should sheet be created anew, by first removing the previous copy if it exists? (default FALSE)

pround

number of significant digits in test p-value representation. Default 3.

Value

The function returns invisibly, after writing the data into sheet and saving the file.

Details

This function performs a one-way contingency table, also calculating the distribution in percents.

The table is then exported to worksheet sheet in workbook wb, either using the format "Count(percent)" (if combine=TRUE), or as two separate columns in the same table.

See the XLtwoWay help page, for behavior regarding new-sheet creation, overwriting, etc.

See Also

If interested in other descriptive summaries, see XLunivariate. For two-way contingency tables, see XLtwoWay.

Examples

Run this code
# NOT RUN {
book1<-XLwriteOpen("chick1.xls") 
XLoneWay(book1,"Diets",ChickWeight$Diet)
### Now in separate columns, and with a title - note it shifts the table down.
### Also adding a Chi-Square goodness of fit (GoF) test vs. a 2:1:1:1 allocation
XLoneWay(book1,"Diets",ChickWeight$Diet,combine=FALSE,row1=10,
         rowTitle="Diet",title="Counts by Diet:",testname='chisq.test',p=c(2,1,1,1)/5)
cat("Look for",paste(getwd(),"chick1.xls",sep='/'),"to see the results!\n")
# }

Run the code above in your browser using DataLab