View source: R/subset_rows_DT.R
subset_rows_DT | R Documentation |
Subset rows of a data.table by reference
subset_rows_DT(DT, idxs, delete_idxs = FALSE)
DT |
The |
idxs |
An |
del.idxs |
FALSE by default to get a positive and return the selected rows. Set to FALSE for deleting rows. |
A positive (or negative) subset of the input data.table
.
#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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.