How to select only the last row among the subset of rows satisfying a condition in R programming

后端 未结 3 1175
被撕碎了的回忆
被撕碎了的回忆 2021-01-28 17:57

The dataframe looks like this :

Customer_id A B C D E F G
10000001    1 1 2 3 1 3 1
10000001    1 2 3 1 2 1 3
10000002    2 2 2 3 1 3 1
10000002    2 2 1 4 2 3 1         


        
3条回答
  •  北荒
    北荒 (楼主)
    2021-01-28 18:26

    Something like this (hard to code without the data in R format):

    dataframe[ rev(!duplicated(rev(dataframe$Customer_id))),]
    

    or better

    dataframe[ !duplicated(dataframe$Customer_id,fromLast=TRUE),]
    

提交回复
热议问题