https://github.com/cran/Epi
Tip revision: b69dff2a729e41a46c7ba595fd9f1daa5cf05c20 authored by Bendix Carstensen on 03 April 2006, 00:00:00 UTC
version 0.6.2
version 0.6.2
Tip revision: b69dff2
ncut.Rd
\name{ncut}
\alias{ncut}
\title{
Function to group a variable in intervals.}
\description{
Cuts a continuous variable in intervals. As opposed to \code{cut}
which returns a factor, \code{ncut} returns a numeric variable.
}
\usage{
ncut(x, breaks, type="left" )
}
\arguments{
\item{x}{A numerical vector.}
\item{breaks}{Vector of breakpoints. \code{NA} will results for values
below \code{min(x)} if \code{type="left"}, for values
above \code{max(x)} if \code{type="right"} and for values
outside \code{range(x)} if \code{type="mid"}}
\item{type}{Character: one of \code{c("left","right","mid")},
indicating whether the left, right or midpoint of the intervals
defined in breaks is returned.}
}
\details{
The function uses the base function \code{findInterval}.
}
\value{
A numerical vector of the same length as \code{x}.
}
\author{
Bendix Carstensen, Steno Diabetes Center, \email{bxc@steno.dk},
\url{http://www.biostat.ku.dk/~bxc/}, with essential input
from Martyn Plummer, IARC.
}
\seealso{
\code{\link{cut}}, \code{\link{findInterval}}
}
\examples{
br <- c(-2,0,1,2.5)
x <- c( rnorm( 10 ), br, -3, 3 )
cbind( x, l=ncut( x, breaks=br, type="l" ),
m=ncut( x, breaks=br, type="m" ),
r=ncut( x, breaks=br, type="r" ) )[order(x),]
x <- rnorm( 200 )
plot( x, ncut( x, breaks=br, type="l" ), pch=16, col="blue", ylim=range(x) )
abline( 0, 1 )
abline( v=br )
points( x, ncut( x, breaks=br, type="r" ), pch=16, col="red" )
points( x, ncut( x, breaks=br, type="m" ), pch=16, col="green" )
}
\keyword{manip}