del_dt_rows | R Documentation |
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.
del_dt_rows(dtb, indx_to_del, dt_env = .GlobalEnv)
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. |
Invisibly returns the updated data.table with the specified rows removed.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.