Last data update: 2014.03.03

R: Units Attribute of a Vector
unitsR Documentation

Units Attribute of a Vector

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

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

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

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Hmisc)
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

> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/Hmisc/units.Rd_%03d_medium.png", width=480, height=480)
> ### Name: units
> ### Title: Units Attribute of a Vector
> ### Aliases: units units.default units.Surv units<-.default
> ### Keywords: utilities interface
> 
> ### ** Examples
> 
> fail.time <- c(10,20)
> units(fail.time) <- "Day"
> describe(fail.time)
fail.time [Day] 
      n missing  unique    Info    Mean 
      2       0       2       1      15 

10 (1, 50%), 20 (1, 50%) 
> S <- Surv(fail.time)
> units(S)
[1] "Day"
> 
> label(fail.time) <- 'Failure Time'
> fail.time
Failure Time [Day] 
[1] 10 20
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>