keep: Keep Columns from a data.table

Description Usage Arguments Details Examples

Description

This function removes all columns not in the set of column names passed.

Usage

1
keep(DT, ..., list = NULL)

Arguments

DT

A data.table object.

...

A set of (quoted or unquoted) variable names.

list

Optional: a list, or vector, of variable names from which to search DT for variables to delete.

Details

Note: only one of the ... and list arguments may be used at a time.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
local({
DT <- data.table( x=1:5, y=letters[1:5], z=factor( letters[1:5] ) )
DT2 <- copy(DT)
str(DT)
keep(DT2, x)
str(DT2)
vars_to_keep <- c("y", "q")
keep(DT, list=vars_to_keep)
str(DT)
})

kevinushey/data.table.extras documentation built on May 20, 2019, 9:09 a.m.