Units Attribute of a Vector
units.RdSets or retrieves the "units" attribute of an object.
For units.default replaces the builtin
version, which only works for time series objects. If the variable is
also given a label, subsetting (using [.labelled) will
retain the "units" attribute. For a Surv object,
units first looks for an overall "units" attribute, then
it looks for units for the time2 variable then for time1.
When setting "units", value is changed to lower case and any "s" at
the end is removed.
Usage
units(x, ...)
# Default S3 method
units(x, none='', ...)
# S3 method for class 'Surv'
units(x, none='', ...)
# Default S3 method
units(x) <- valueValue
the units attribute of x, if any; otherwise, the units attribute of
the tspar attribute of x if any; otherwise the value
none. Handling for Surv objects is different (see above).
Examples
require(survival)
fail.time <- c(10,20)
units(fail.time) <- "Day"
describe(fail.time)
#> fail.time [Day]
#> n missing distinct Info Mean
#> 2 0 2 1 15
#>
#> Value 10 20
#> Frequency 1 1
#> Proportion 0.5 0.5
S <- Surv(fail.time)
units(S)
#> [1] "Day"
label(fail.time) <- 'Failure Time'
units(fail.time) <- 'Days'
fail.time
#> Failure Time [Dayss]
#> [1] 10 20