jfreq {lazy.tools}R Documentation

Joint Frequency Distribution of Discrete Variables

Description

Joint Frequency Distribution of Discrete Variables

Usage

jfreq(X, weight = NULL, omitmiss = 1, sort = 0)

Arguments

X

Input multivariate discrete data

weight

weight vector or 1

omitmiss

= 0 to return the cartesian product of unique values of each column of X.

sort

= 1 to sort so that the last column changes first.
= 2 to sort by frequency in ascending order
= 3 to sort by frequency in descending order

Details

Calculates the frequency of the unique rows of X matrix.
Note, however, the order of the rows are different from the reslt of unique(X) which does not sort the result.
If sort=0, the first column changes first, otherwise, the last column changes first.

Value

A list of:
Xu An object consisting of the (sorted) unique rows of X
f Assosiated frequency vector

Examples

# numeric varaibles
set.seed(1701)
X <- matrix(sample(0:1,50,replace=1),25)
X <- cbind(X,matrix(sample(1:2,50,replace=1),25))
X <- rbind(X,matrix(c(0,1,0,1),5,4,byrow=1))
colnames(X) <- paste("ccc",1:4,sep="")
res <- jfreq( X )
Print( res$Xu, res$f )

# sort so that the last column changes first
res1 <- jfreq( X, sort=1 )
Print( res1$Xu, res1$f )

# sort by frequency
res1 <- jfreq( X, sort=3 )
Print( res1$Xu, res1$f )

# mixed variable types in a data.frame
Y <- as.data.frame(X)
Y[,2] <- letters[Y[,2]+1]
res2 <- jfreq( Y )
Print( res2$Xu, res2$f )


[Package lazy.tools version 0.1.4 ]