lapply_dt: Flexibly apply function to columns of data.table/frame

View source: R/package.R

lapply_dtR Documentation

Flexibly apply function to columns of data.table/frame

Description

Convenience function to apply a function to columns of a data.table/frame. The syntax for the columns is flexible

Usage

lapply_dt(
  x,
  dt,
  LFUN = "identity",
  natype = NA,
  as.data.table = T,
  evalcall = FALSE
)

Arguments

x

fields to apply function to

dt

data.table/frame

LFUN

either a character name of a function, or a function

natype

the type of NA which is to be specified as one of NA, NA_character_, NA_real_, or NA_integer_

as.data.table

a logical indicating whether to coerce the output to a data.table

evalcall

logical flag to evaluate x as a call or not

Details

lapply_dt(c(newcolname = colname), dt, dosomething) will give a data.table or list with the column name renamed to newcolname lapply_dt(.(newcolname = colname)...) also works as well. Note that no quotations are needed.

Value

data.table/frame if as.data.table is TRUE, otherwise a list


kevinmhadi/khtools documentation built on Jan. 16, 2025, 4:18 p.m.