data.table (version 1.6.2)

transform.data.table: Data table utilities

Description

Utilities for data.table transformation.

Usage

## S3 method for class 'data.table':
transform(`_data`, \ldots)
## S3 method for class 'data.table':
within(data, expr, keep.key = FALSE, \ldots)

Arguments

data, _data
data.table to be transformed.
...
for transform, Further arguments of the form tag=value. Ignored for within.
expr
expression to be evaluated within the data.table.
keep.key
logical; if TRUE, keep the sorted key.

Value

  • The modified value of data.

Details

within is like with, but modifications (columns changed, added, or removed) are updated in the returned data.table.

Note that transform always removes the key, and within has an option to keep it.

See Also

transform and within

Examples

Run this code
dt <- data.table(a=rep(1:5, 1), b=1:10)

transform(dt, c = a^2)

within(dt, {
  b <- rev(b)
  c <- a^2
  rm(a)
})

# dt[, transform, c = max(b), by="a"]  # like "ave"

Run the code above in your browser using DataCamp Workspace