Skip to content
Prev 38165 / 398500 Next

indexing a vector

On Thu, 2003-10-02 at 12:40, morozov wrote:
You might want to look at ?cut, which returns a factor based upon
defining breakpoints in a continuous vector. You can break the vector
'x' and relabel the levels to give you what you need.

For example:

x <- rnorm(100)

MyLevels <- factor(cut(x, quantile(x), include.lowest = TRUE), 
                   labels = 1:4)

table(MyLevels)
MyLevels
 1  2  3  4
25 25 25 25

HTH,

Marc Schwartz