rank2group {moonBook} | R Documentation |
rank a numeric vector and returns a new ordinal vector
Description
rank a numeric vector and returns a new ordinal vector
Usage
rank2group(y, k = 4)
Arguments
y |
a numeric vector |
k |
a integer specifies how many groups you want to classify. default value is 4 |
Value
a ordinal vector(numeric) with the same length of y
Examples
require(ggplot2)
data(diamonds)
diamonds$PriceGroup=rank2group(diamonds$price,4)
table(diamonds$PriceGroup)
aggregate(price~PriceGroup,data=diamonds,range)
diamonds$PriceGroup3=rank2group(diamonds$price,3)
table(diamonds$PriceGroup3)
aggregate(price~PriceGroup3,data=diamonds,range)
diamonds$PriceGroup5=rank2group(diamonds$price,5)
table(diamonds$PriceGroup5)
aggregate(price~PriceGroup5,data=diamonds,range)
[Package moonBook version 0.3.1 Index]