ncut {Epi} | R Documentation |
Cuts a continuous variable in intervals. As opposed to cut
which returns a factor, ncut
returns a numeric variable.
ncut(x, breaks, type="left" )
x |
A numerical vector. |
breaks |
Vector of breakpoints. Values ouside range(x) will be
NA . |
type |
Character: one of c("left","right","mid") ,
indicating whether the left, right or midpoint of the intervals
defined in breaks is returned. |
The function uses the base function findInterval
.
A numerical vector of the same length as x
.
Bendix Carstensen, Steno Diabetes Center, bxc@steno.dk, http://www.biostat.ku.dk/~bxc/, with essential input from Martyn Plummer, IARC.
br <- c(-2,0,1,2.5) x <- c( rnorm( 10 ), br, -3, 3 ) cbind( x, ncut( x, breaks=br, type="l" ), ncut( x, breaks=br, type="m" ), ncut( x, breaks=br, type="r" ) ) 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" )