renameRange: Rename data range labels

Description Usage Arguments Details Value Author(s) Examples

Description

We usually use cut to cut continuous vectors into factors. But the levels are typically presented as '[l, u)' or '(l, u]'. This function can reformat the cut results.

Usage

1
2
3
4
5
renameRange(x, quick.form = c("-", "~", "[)", "(]", "<=", ">="),
  format = NULL, left.subtract = 0, right.subtract = 0, ...)

relab_range(x, quick.form = c("-", "~", "[)", "(]", "<=", ">="),
  format = NULL, left.subtract = 0, right.subtract = 0, ...)

Arguments

x

The factor vector yielded by cut function.

quick.form

A string to define the new format.

-

equivalent to format="x-y": 0-10, 10-20, 20-30

~

equivalent to foramt="x~y": 0~10, 10~20, 20~30

[)

equivalent to foramt="[x, y)": [0, 0), [10, 0), [20, 0)

(]

equivalent to foramt="(x, y]": (0, 0], (10, 0], (20, 0]

<=

equivalent to foramt=c("<=y", "x-y", ">x"): <=9, 10-19, 20-29, >29

>=

equivalent to foramt=c("<y", "x-y", ">=x"): <10, 10-20, 20-30, >=30

format

Self-defined character vector length 1-3 to format the label. If more than 3 character elements are given, the function will only use the first 3. Default NULL, and quick.form is applied. See details.

left.subtract

Integer which is subtracted from the left limit of each range. Default 0.

right.subtract

Integer which is subtracted from the right limit of each range. Default 0.

...

ignore

Details

All the format definitions should use "x" to represent the lower limit and "y" to reresent the upper limit of each range label. For instance, 'x-y' coereces '(0, 1]' to '0-1', '<y' coerces '(0, 1]' to '<1'.

By principle, it should be of length 3: beginning label, middle label(s) and end label. But there could be shortened forms:

Value

A new factor vector with reformatted levels.

Author(s)

Yiying Wang, wangy@aetna.com

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## Not run: 
x = cut(1:100, c(0, 20, 40, 60, 80, 100))
renameRange(levels(x), "-")
# [1] "0-20"   "20-40"  "40-60"  "60-80"  "80-100"

renameRange(levels(x), "[)")
# [1] "[0, 20)"   "[20, 40)"  "[40, 60)"  "[60, 80)"  "[80, 100)"

renameRange(levels(x), ">=", left.substract = -1)
# [1] "<20"   "21-40"  "41-60"   "61-80"  "\u226581"
 
relab_range(levels(x), format=c(" ~ y", "x ~ y", "x ~ "))
# [1] " ~ 20"   "20 ~ 40" "40 ~ 60" "60 ~ 80" "80 ~ "  

## End(Not run)

madlogos/aseshms documentation built on May 21, 2019, 11:03 a.m.