# generic function ftable(x, ...) ## Default S3 method: ftable(..., exclude = c(NA, NaN), row.vars = NULL, col.vars = NULL) ## S3 method for class 'formula': ftable(formula, data = NULL, subset = NULL, na.action = getOption("na.action", default="na.fail"), ...) ## S3 method for class 'ftable': print(x, digits = getOption("digits"), ...) ## S3 method for class 'ftable': format(x, quote = TRUE, digits = getOption("digits"), ...) ## S3 method for class 'ftable': as.table(x, ...) ## S3 method for class 'ftable': as.data.frame(x, row.names = NULL, optional = FALSE, ...)
x |
In ftable, this argument could be a list, or a data frame, or a table object of
class "table" or "ftable", or a formula object. In other methods *.ftable, this argument is an object of class "ftable". |
... |
In ftable and ftable.default, this argument could be one or more objects,
each to be interpreted as a factor. All arguments must be of equal length. If this is a single
argument (that is, a list, or a data frame, or a contingency table object of class "table"
or "ftable".), each of its components is interpreted as a factor. Together, the arguments
define a multi-way ragged array of as many dimensions as there are arguments. In ftable.formula and other methods *.ftable, this argument is(are) other optional argument(s) passed to or from these functions. |
exclude | a vector of objects to exclude from forming levels when converting input vectors to factors before tabulating them. This argument is passed to function table and thus is only used if an argument to table is not a factor. |
row.vars | a character vector specifying the names or an integer vector specifying the numbers, of the variables to be used for the rows of the flat contingency table. If only one of row.vars and col.vars is supplied, the missing one is assumed to be all the names in the data argument except the names in the nonmissing argument. |
col.vars | a character vector specifying the names or an integer vector specifying the numbers, of the variables to be used for the columns of the flat contingency table. |
formula | a two-sided formula. The names to the left of the tilde are the col.vars and those the the right row.vars. The formula should contain only addition signs, names, and a tilde except that (a) a literal 1 on one side of the formula is used as a placeholder to indicate that there are no variables on that side of the formula and (b) a literal dot, ., is replaced by all the variables in the data that are not explicitly mentioned in the formula (only done when data is a ftable or table object) |
data | a data.frame, ftable, or table object that contains the objects named in formula. |
subset | an expression that specifies a subset from the data.frame data to use in formula. It is evaluated in the same environment as the formula is, so it can involve variables in the data.frame. A missing subset argument or subset=NULL means to use the entire data.frame. subset is ignored when data is a table or ftable object. |
na.action | a character string that specifies how missing values ("NA"s) are handled. By default, an error is returned. It is ignored when data is a table or ftable object. |
digits | the number of significant digits that should be printed or formatted. The default is the value of option "digits". This is only used when the numbers in the table are not integral. |
quote | a logical value. If set to TRUE(the default), the strings in the row and column name information are formatted with surrounding quotes. (The data in the table is self is never quoted.) |
row.names | a (character) vector giving row names for the data frame. Refer to as.data.frame for more information. |
optional | a logical value. Refer to as.data.frame for more information. |
Pet <- c("Cat","Dog","Cat","Dog","Cat","Fish") Food <- c("F1","F3","F2","F4","F2","F4") Sex <- c("M", "M", "F", "M", "F", "F") Color <- c("Black", "White", "Yellow", "NA", "White", "Black" ) ft <- ftable(Pet, Food, Sex, Color) ft ft3 <- ftable(ft, row.vars = "Food", col.vars = c("Sex", "Pet")) ft3 as.table(ft3)M <- with(Sdatasets::solder, tapply(skips, list(Opening=Opening, Solder=Solder, PadType=PadType), FUN=mean)) print(ftable(M, row.vars=c("PadType", "Solder")), digits=2)
Admissions <- array(c(93, 56, 54, 98, 46, 96, 63, 72, 65, 33, 10, 41, 30, 50, 66, 61, 87, 84, 38, 36), dim=c(2, 2, 5), dimnames=list(Admit=c("Admitted", "Rejected"), Gender=c("Male", "Female"), Dept=LETTERS[1:5])) z <- ftable(Dept ~ ., data = Admissions) ftable(Admit ~ Dept + Gender, data = z) as.data.frame(z)