Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

drop_units

Drop Units


Description

Drop units attribute and class.

Usage

drop_units(x)

## S3 method for class 'units'
drop_units(x)

## S3 method for class 'data.frame'
drop_units(x)

## S3 method for class 'mixed_units'
drop_units(x)

Arguments

x

an object with units metadata.

Details

Equivalent to units(x) <- NULL, or the pipe-friendly version set_units(x, NULL), but drop_units will fail if the object has no units metadata. Use the alternatives if you want this operation to succeed regardless of the object type.

A data.frame method is also provided, which checks every column and drops units if any.

Value

the numeric without any units attributes, while preserving other attributes like dimensions or other classes.

Examples

x <- 1
y <- set_units(x, m/s)

# this succeeds
drop_units(y)
set_units(y, NULL)
set_units(x, NULL)

## Not run: 
# this fails
drop_units(x)

## End(Not run)

df <- data.frame(x=x, y=y)
df
drop_units(df)

units

Measurement Units for R Vectors

v0.7-1
GPL-2
Authors
Edzer Pebesma [aut, cre] (<https://orcid.org/0000-0001-8049-7069>), Thomas Mailund [aut], Tomasz Kalinowski [aut], James Hiebert [ctb], Iñaki Ucar [aut] (<https://orcid.org/0000-0001-6403-5550>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.