Defines functions del_rows

Documented in del_rows

#' del_rows
#' Deletes rows in X. Caution: Retains keys but some stuff is lost, at least indices
#' @param X data.table
#' @param delete integer vector of rows to be deleted (use either this or keep)
#' @param keep integer vector of rows to keep (use either this or delete)
#' @param envir environment of where X resides. Must be specified if X is NOT in global envir. 
# Function to delete rows:
del_rows <- function(X,delete,keep=-delete,envir=.GlobalEnv) {
  name_of_X <- deparse(substitute(X))
  X_names <- copy(names(X))
  keyv <- key(X)
  X_new <- X[keep,X_names[1L],with=F]
  for(j in seq_len(length(X_names) - 1L)) {
    set(X_new,i=NULL,j=X_names[1L+j],value=X[[1L]][keep] )
  if(!is.null(keyv)) setkeyv(X_new,keyv)
  assign(name_of_X,value=X_new, envir = envir)
matthiaskaeding/Kaeding documentation built on May 6, 2019, 8:50 a.m.