选择组
# example data
DT = data.table(Titanic)
假设我们只想看第二堂课:
DT[ Class == "2nd" ]
# Class Sex Age Survived N
# 1: 2nd Male Child No 0
# 2: 2nd Female Child No 0
# 3: 2nd Male Adult No 154
# 4: 2nd Female Adult No 13
# 5: 2nd Male Child Yes 11
# 6: 2nd Female Child Yes 13
# 7: 2nd Male Adult Yes 14
# 8: 2nd Female Adult Yes 80
在这里,我们简单地使用 i
(where
子句)对数据进行子集化。