Two ways to subsetting rows in a data.table

发布时间 2023-07-13 20:37:54作者: DaqianLU

Q: In the flights dataset, subsetting all the rows in which the planes take off from LGA and land in TPA.

  • By i
flights[origin == "LGA" & dest == "TPA", ]
  • By key
    setkeyv(flights, c("origin", "dest"))
    flights[.("LGA", "TPA"), ]