数据表中的子集

问题描述:

我试图将data.table子集(从包 data.table )in R(not a data.frame)。我有一个4位数年作为关键。我想通过采取一系列的年子集。

I am trying to subset a data.table ( from the package data.table ) in R (not a data.frame). I have a 4 digit year as a key. I would like to subset by taking a series of years. For example, I want to pull all the records that are from 1999, 2000, 2001.

我已经尝试传入我的 DT [J年)] 二进制搜索语法如下:

I have tried passing in my DT[J(year)] binary search syntax the following:

1999,2000,2001
c(1999,2000,2001)
1999, 2000, 2001

工作。

什么工作对于任何人都知道如何做一个子集,你想选择的年份不只是1, data.frame 适用于 data.table

What works for data.frames works for data.tables.

subset(DT, year %in% 1999:2001)