set_functions: set functions for multiple column alterations using...

Description Usage Arguments Note Examples

Description

This function updates by reference multiple columns by applying a desired function such as numeric, factor using functions in the same manner as apply(), or with . as a placeholder.

Usage

1
setf(x, j, value, ...)

Arguments

x

A data.table. Or, set() accepts data.frame, too. If you are creating new columns, x should be a data.table.

i Is left out of this function.

j

Column name(s) (character) or number(s) (integer) to be assigned value when column(s) already exist, and only column name(s) if they are to be added newly. Additionally, assigning j = 'all' will automatically reference all columns in the data.table.

value

A list of replacement values to assign by reference to x[i, j]. In addition, functions can be passed into the value argument as well with subsquent arguements in the same way as apply functions.

...

Is used to pass arguments into the value "function" if you choose to apply a function instead of updating the data with a replacement vector or list. If you choose to place a . at any point within the sequence of additional arguements passed into the value argument, the . will act as a placeholder for the jth column.

Note

These functions are for convenience only.

Examples

1
2
3
4
5
6
dt <- d.t(x = 0:10, y = 10:20)
setf(dt, j = c("x2","y"), value = paste0,  ., "hello", "would")
print(dt)
df2 <- d.f(x = 0:10, y = 10:20)
setf(df2, j = c("x","y"), value = paste0,  ., "hello", "would")
print(df2)

equastat/Emisc documentation built on May 16, 2019, 8:24 a.m.