statar (version 0.1.1)

setmutate_each: Version of mutate_each that (i) transforms data.table in place (ii) allows by, i condition (iii) when only when fun, creates new variables - except when replace = TRUE

Description

Version of mutate_each that (i) transforms data.table in place (ii) allows by, i condition (iii) when only when fun, creates new variables - except when replace = TRUE

Usage

setmutate_each(x, funs, ..., i = NULL, by = NULL, replace = FALSE)

setmutate_each_(x, funs, vars, i = NULL, by = NULL, replace = FALSE)

Arguments

x
a data.table
funs
List of function calls, generated by funs, or a character vector of function names.
...
Variables to include. Defaults to all non-grouping variables.
i
a condition that restricts the set of row on which to apply the function
by
Groups within which the function should be applied
replace
If replace = TRUE, variables are replaced. Default to FALSE (new variable are created)
vars
Used to work around non-standard evaluation.

Examples

Run this code
library(data.table)
library(dplyr)
N <- 100
DT <- data.table(
  id = sample(5, N, TRUE),
  v1 = sample(5, N, TRUE),
  v2 = sample(1e6, N, TRUE)
)
setmutate_each(DT, funs(mean, mean_na = mean(., na.rm = TRUE)), v2, i = id ==1, by = v1)
setmutate_each(DT, funs(as.character), replace = TRUE)

Run the code above in your browser using DataCamp Workspace