【发布时间】:2018-07-09 22:42:29
【问题描述】:
所以我有以下数据表:
Name | Addr | Age
-------------------
Bill | 2112 W | 17
Barb | 2112 W | 16
Rick | 3445 E | 16
Chad | 2112 W | 5
Ruth | 5567 S | 4
Mick | 3445 E | 17
Hank | 3445 E | 1
Lace | 1111 S | 16
Nick | 2112 W | 4
我想添加一个计算列,检查满足以下条件的行数是否大于 2:地址相同且年龄大于 15 的所有行,因此新表将是:
Name | Addr | Age | Count
---------------------------
Bill | 2112 W | 17 | TRUE #There are two people at addr 2112 W over 15, so True
Barb | 2112 W | 16 | TRUE #There are two people at addr 2112 W over 15, so True
Rick | 3445 E | 16 | TRUE #There are two people at addr 3445 E over 15, so True
Chad | 2112 W | 5 | TRUE #There are two people at addr 2112 W over 15, so True
Ruth | 5567 S | 4 | FALSE #No one at 5567 S is over 15, so False
Mick | 3445 E | 17 | TRUE #There are two people at addr 3445 E over 15, so True
Hank | 3445 E | 1 | TRUE #There are two people at addr 3445 E over 15, so True
Lace | 1111 S | 16 | FALSE #Only one person over 15 is at addr 1111 S, so False
Nick | 5567 S | 16 | FALSE #Two people live at addr, but only one of them is over 15 so False
这是我目前正在尝试的解决方案:
dat$COUNT 15]) >= 2, dat$ADDR)
但这似乎无法正常工作,并且在处理大型数据集时速度非常慢。
【问题讨论】: