max(start_date)に基づいてRの各グループのデータフレームの最後の行を削除します。Rグループごとにデータフレームの最後の行を削除します
例データ:
id start_date end_date
1 2016-01-14 2016-02-14
1 2016-03-14 2016-08-05
2 2014-01-14 2014-02-14
2 2015-03-21 2015-05-21
2 2015-08-23 2015-09-23
2 2015-11-21 2016-01-03
結果:
id start_date end_date
1 2016-01-14 2016-02-14
2 2014-01-14 2014-02-14
2 2015-03-21 2015-05-21
2 2015-08-23 2015-09-23
次は動作しません:
df <- df %>%
group_by(id) %>%
summarise(start_date != max(start_date))
エラー:見つかった重複した列名:ID
df <- sqldf("select * from df group by id having start_date != max(start_date)")
を
ステートメント内のエラー:重複する列名:id
いずれかの提案は素晴らしいでしょう。日付は「couldn(以前のいくつかのベンチマークに基づいて、その後、arrange
とslice
df1 %>%
group_by(id) %>%
arrange(start_date) %>%
slice(-n())
を注文していない場合
私たち – mtoto
SQLでは、相関クエリを使用します。 'sqldf(" select * from df a where start_dateは(d_bからb_id = aを選択してmax(start_date)を選択します。 id) ")' –