0

Is there a way to filter rows of a data.table in-place, i.e. without assigning it to a variable name?

library(data.table)
df <- data.table(a=1:5)

For example, can we do this without an assignment to df?

df <- df[a>3]
otwtm
  • 1,779
  • 1
  • 16
  • 27
  • What do you mean? Not creating an object (in this case, what you called df)? You can, if this is what you mean, do `data.table(a=1:5)[a>3]` – rg255 May 05 '20 at 10:57
  • https://stackoverflow.com/questions/17891519/is-it-possible-to-modify-a-data-frame-in-place-destructively – emrhzc May 05 '20 at 11:00
  • 1
    I think this would be equivalent to "deleting rows by references": https://github.com/Rdatatable/data.table/issues/635 https://stackoverflow.com/questions/10790204/how-to-delete-a-row-by-reference-in-data-table/10791729#10791729 – desval May 05 '20 at 11:07
  • @rg255, no, what I meant is can we do this `df<-df[a>3]` in-place, meaning without writing `df` twice. But apperently this was asked before. – otwtm May 05 '20 at 11:07

0 Answers0