del_dt_rows: Delete specified rows from a data.table

View source: R/dt_ops.R

del_dt_rowsR Documentation

Delete specified rows from a data.table

Description

This function removes rows from a data.table based on specified indices. It creates a new data.table containing only the rows that are retained, preserves the original key, and then reassigns the updated data.table back to its original variable in the specified environment.

Usage

del_dt_rows(dtb, indx_to_del, dt_env = .GlobalEnv)

Arguments

dtb

A data.table from which rows will be deleted.

indx_to_del

An integer vector indicating row positions to delete, or a logical vector where TRUE indicates rows to delete.

dt_env

The environment where the data.table is stored; default is .GlobalEnv.

Value

Invisibly returns the updated data.table with the specified rows removed.

Examples

library(data.table)
dtb <- data.table(a = 1:5, b = letters[1:5])
# Delete the 2nd and 4th rows
del_dt_rows(dtb, c(2, 4))
# Alternatively, using a logical vector to delete rows where 'a' is even
del_dt_rows(dtb, dtb$a %% 2 == 0)

ChristK/CKutils documentation built on April 11, 2025, 10:11 p.m.