expand_freqdist {lazy.tools}R Documentation

Expand Frequency Distribution to Raw Data

Description

Expand Frequency Distribution to Raw Data

Usage

expand_freqdist(fd, weight = NULL)

Arguments

fd

tables, matrices or data.frames containing frequency distribution (midpoints,freq).

weight

Frequency count of each row of fd.
If null, fd[,ncol(fd)] will be used as the weight.

Details

In univariate case, this function returns
unlist( mapply( function(x,y) rep(x,y), fd[,1], fd[,2] ) )

Value

A vector of length( sum(weight) ) or matrix with nrow=sum(weight)

Examples

# univariate
seed <- 1701
set.seed(seed)
# univariate
tab1 <- table( sample(letters[1:5], 20, replace=1) )
res1 <- expand_freqdist( tab1 )
Print(tab1,res1)

# multivariate
tab2 <- table( x=sample(letters[1:5], 20, replace=1)
   , sample(6:8, 20, replace=1) )
res2 <- expand_freqdist( tab2 )
Print(tab2,res2)


[Package lazy.tools version 0.1.3 Index]