【发布时间】:2014-09-26 12:06:38
【问题描述】:
我有一个看起来像这样的数据框
deltnr 我们stone_ny stone_mobility 1535 63 no_stone NA 1994-09-21 男性 60 1536 61 no_stone NA 1983-09-06 男性 60 1536 62 no_stone NA 1988-08-18 男性 60 1536 63 石头手机 1994-03-04 男 70 154 61 no_stone NA 1983-06-22 男性 40 154 62 no_stone NA 1988-06-08 男性 45 1543 61 no_stone NA 1983-08-17 女性 30 1543 62 no_stone NA 1988-08-17 女性 35 1336 61 no_stone NA 1983-08-22 男性 60 1336 62 石头手机 1988-11-04 男 65我想在stone_ny 变量中提取所有带有deltnr 和“stone”的独特观察结果。我的问题在于每个 deltnr 都有多个观察结果。我试过 unique() 和 subset() 没有运气。
【问题讨论】:
-
您的数据框的
dput可能会使这些列更易辨认。 -
@Daniel 假设您在
stone_ny中有多个stone用于deltnr组,并且其他列不同。在这种情况下,您选择哪个观察/行?unique(dat[dat$stone_ny=="stone",])将为每个deltnr组提供多个stone。 -
我想选择第一个也是唯一一个“我们”。正是这就是我出错的地方。你知道出路吗?
-
@Daniel 这是否意味着如果你有两个
us和65和70和stone和1336,你会选择第一个还是两个观察?我猜你的意思是us相同时的第一次观察?