statar (version 0.1.1)

setcols: Retain certain columns of a data.table in place (= Stata keep).

Description

Retain certain columns of a data.table in place (= Stata keep).

Usage

setcols(x, ...)

setcols_(x, ..., .dots)

Arguments

x
a data.table
...
Variables to keep. See the select documentation.
.dots
Used to work around non-standard evaluation.

Examples

Run this code
library(data.table)
DT <- data.table(
  id = c(1,2),
  v1 = c(1,1),
  v2 = c(2,1)
)
setcols(DT, id, v2)
setcols(DT, -id)

Run the code above in your browser using DataCamp Workspace