Description Arguments Value Author(s) See Also Examples

fulltable attaches margins and NA/NaN category to the output of table()

same as table()

same as returned from table()

Hormuzd A. Katki

table

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | ```
## The function is currently defined as
function (...)
{
## Purpose: Add the margins automatically and don't exclude NA/NaN as its own row/column
## and also add row/column titles. Works for mixed numeric/factor variables.
## For factors, the exclude option won't include the NAs as columns, that's why
## I need to do more work.
## ----------------------------------------------------------------------
## Arguments: Same as for table()
## ----------------------------------------------------------------------
## Author: Hormuzd Katki, Date: 5 May 2006, 19:45
# This works for purely numeric input, but not for any factors b/c exclude=NULL won't
# include NAs for them.
# return(addmargins(table(...,exclude=NULL)))
##
# Factors are harder. I have to reconstruct each factor to include NA as a level
##
# Put everything into a data frame
x <- data.frame(...)
# For each factor (in columns), get the raw levels out, reconstruct to include NAs
# That is, if there are any NAs -- if none, add it as a level anyway
for (i in 1:dim(x)[2]) {
if ( is.factor(x[,i]) )
if ( any(is.na(x[,i])) )
x[,i] <- factor(unclass(x[,i]),labels=c(levels(x[,i]),"NA"),exclude=NULL)
else
levels(x[,i]) <- c(levels(x[,i]),"NA")
}
# Make table with margins. Since NA is a level in each factor, they'll be included
return(addmargins(table(x,exclude=NULL)))
}
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.