数据表中的子集 [英] subsetting in data.table

查看:93
本文介绍了数据表中的子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将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)

这篇关于数据表中的子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆