units: Units Attribute of a Vector

Description Usage Arguments Value See Also Examples

View source: R/units.s

Description

Sets 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.

Usage

1
2
3
4
5
6
7
units(x, ...)
## Default S3 method:
units(x, none='', ...)
## S3 method for class 'Surv'
units(x, none='', ...)
## Default S3 replacement method:
units(x) <- value

Arguments

x

any object

...

ignored

value

the units of the object, or ""

none

value to which to set result if no appropriate attribute is found

Value

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).

See Also

label

Examples

1
2
3
4
5
6
7
8
fail.time <- c(10,20)
units(fail.time) <- "Day"
describe(fail.time)
S <- Surv(fail.time)
units(S)

label(fail.time) <- 'Failure Time'
fail.time

Example output

Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package: 'Hmisc'

The following objects are masked from 'package:base':

    format.pval, round.POSIXt, trunc.POSIXt, units

fail.time [Day] 
       n  missing distinct     Info     Mean      Gmd 
       2        0        2        1       15       10 
                  
Value       10  20
Frequency    1   1
Proportion 0.5 0.5
[1] "Day"
Failure Time [Day] 
[1] 10 20

Hmisc documentation built on Jan. 4, 2018, 3:22 a.m.