ncut | 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. |
type |
Character: one of |
The function uses the base function findInterval
.
A numerical vector of the same length as x
.
Bendix Carstensen, Steno Diabetes Center, b@bxc.dk, http://bendixcarstensen.com, with essential input from Martyn Plummer, martyn.plummer@r-project.org
cut
, findInterval
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" )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.