intro_r/doc/datatable_querying.org

1.6 KiB

Datatable package

Org document with R code

  rm(list = ls())

Querying data.table

Sintaxis:

  • DT[i, j, by]

Subseting by "i" and "j"

Subset rows in "i"

  dt1 <- flights[origin == "JFK" & month == 6L]
  dt1

Get the first two rows

  flights[1:2]
   year month day dep_delay arr_delay carrier origin dest air_time distance
1: 2014     1   1        14        13      AA    JFK  LAX      359     2475
2: 2014     1   1        -3        13      AA    JFK  LAX      363     2475
   hour
1:    9
2:   11

Ordering results of querying

  dt_filt <- flights[order(origin, -dest)]
  dt_filt