table2freqdist {lazy.tools}R Documentation

Convert an output of table or xtabs to a simple frequency table format

Description

Convert an output of table or xtabs to a simple frequency table format

Usage

table2freqdist(tab, omitmiss = 0, index = 1, pat = 2, sort = 1)

Arguments

tab

An output of native table or xtabs function.

omitmiss

= 1 to exclude the zero-freq cells.

index

= 0 to output no level indices

pat

argument to is.number function.

sort

= 0 not to sort the result

Value

When index == 1 and there are nf factors(variables) to be tabulated,
the output is a matrix or data.frame:
the first nf columns of which consist of the level indices, and the nf+1st column contains the frequency count.

If the levels are numeric, a matrix will be returned. Otherwise, a data.frame.
In both cases rownames(fd) contains the combinations of the level names.

Examples

set.seed(1701)
x <- sample(1:8,10,replace=1); x <- c(x,c(1,1,7)); xc <- paste("x",x,sep="")
y <- sample(0:9,10,replace=1); y <- c(y,c(5,5,0)); yc <- paste("y",y,sep="")
z <- sample(5:9,10,replace=1); z <- c(z,c(5,5,9)); zc <- paste("z",z,sep="")

rest1 <- table( x )
rest2 <- table( x, y )
rest3 <- table( xc,y,z )
restx3 <- xtabs( ~xc+yc+z )

table2freqdist( rest1 )
table2freqdist( rest2 )
table2freqdist( rest3, omitmiss=1 )
table2freqdist( restx3, omitmiss=1, index=0 )

tab2 <- table( x=sample( letters[1:5], 20, replace=1)
             , sample(letters[6:8], 20, replace=1) )
table2freqdist( tab2 )


[Package lazy.tools version 0.1.6 ]