subset_rows_DT: Subset rows of a data.table by reference

View source: R/subset_rows_DT.R

subset_rows_DTR Documentation

Subset rows of a data.table by reference

Description

Subset rows of a data.table by reference

Usage

subset_rows_DT(DT, idxs, delete_idxs = FALSE)

Arguments

DT

The data.table to be subsetted.

idxs

An integer vector with row indices for the subset. For a conditional subsets see example below.

del.idxs

FALSE by default to get a positive and return the selected rows. Set to FALSE for deleting rows.

Value

A positive (or negative) subset of the input data.table.

Examples

#conditional deletion of rows
DT = data.table(x=rep(c("b","a","c"),each=3), y=c(1,3,6), v=1:9)
#introduce numbering id if relevant
DT[, id := 1:nrow(DT)]
delete_letters <- c("a", "c")
delete_idxs <- which(DT[,x] %in% delete_letters)
DT_subset <- subset_rows_DT(DT = DT, idxs = delete_idxs, delete_idxs = TRUE)
DT_subset
#    x y v id
# 1: b 1 1  1
# 2: b 3 2  2
# 3: b 6 3  3

manuelbickel/textility documentation built on Nov. 25, 2022, 9:07 p.m.