Description Usage Arguments Details Value Author(s) Examples
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.
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, ...)
|
x |
The factor vector yielded by |
quick.form |
A string to define the new format.
|
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 |
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 |
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:
length 1: all of the same format. E.g., 'x-y'
results in '0-1',
'1-2', '2-3'.
length 2: beginning label and middle label(s). End label is the same with
middle label. E.g, c("<x", "x-y") results in "<0", "1-2", "2-3".
length 3: full-form format
.
A new factor vector with reformatted levels.
Yiying Wang, wangy@aetna.com
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.