data.table (version 1.7.10)

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, \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.

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 will keep the key of the data.table provided the ``targets'' of the transform (i.e. the columns that appear in ...) are not in the key of the data.table. within also retains the key provided the key columns are not ``touched''.

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 DataLab