% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/freqfuncs.R
\name{compress_freqdist}
\alias{compress_freqdist}
\title{Compress Frequency Distribution by Aggregating Duplicate Entries}
\usage{
compress_freqdist(x, freq, fill = 0, domain = NULL)
}
\arguments{
\item{x}{Vector of values (domain of a scalar variable, numeric or string)}

\item{freq}{Vector of frecuencies:
\code{(x, freq)} is the frequency distribution.}

\item{fill}{= 1 to fill the domain}

\item{domain}{Domain of \code{x} to be filled. (coalescing)}
}
\value{
A data frame consisting of \cr
\code{x} Vector of unique values \cr
\code{freq} Vector of frequencies
}
\description{
Compress Frequency Distribution by Aggregating Duplicate Entries
}
\details{
The purpose of this function is to remove the duplicate values of \code{x}
and adjusting the associated frequency count in \code{freq}.

The core part of this function is:
\preformatted{
 fnew <- xtabs( freq ~ x )
 xnew <- names(fnew)
 res <- data.frame(x=xnew, freq=fnew)
}
and if \code{domain} and \code{fill} are given, the result will be
coalesced. (coalescing)  
Using the frequency table below
\preformatted{
 x  freq
 1  1
 2  2
 2  1
 3  1
}
\preformatted{
  compress_freqdist( x, freq, fill=1, domain=0:4)
}
returns
\preformatted{
 x  freq
 0  0
 1  1
 2  3
 3  1
 4  0
}
}
\examples{
x <- c(1,2,4,5,6, 2,4,6, 9 )
f <- c(1,2,2,1,2, 1,2,1, 1 )

( res <- compress_freqdist( x, f ) )
( res <- compress_freqdist( x, f, fill=1, domain=0:10 ) )


xc <- letters[c(1,2,4,5,6, 2,4,6, 9 )]
f <- c(1,2,2,1,2, 1,2,1, 1 )
( res <- compress_freqdist( xc, f ) )
( res <- compress_freqdist( xc, f, fill=1, domain=letters[0:10] ) )

}
