rank2group: rank a numeric vector and returns a new ordinal vector

Description Usage Arguments Value Examples

Description

rank a numeric vector and returns a new ordinal vector

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
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)

moonBook documentation built on Jan. 5, 2022, 9:06 a.m.