Two ways to subsetting rows in a data.table

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"), ]

     

posted @ 2023-07-13 20:32  DaqianLU  阅读(11)  评论(0)    收藏  举报