Delete all rows coresponding to given ID

前端 未结 3 897
别跟我提以往
别跟我提以往 2021-01-27 06:21

Data overview:

> str(dataStart[c(\"gvkey\",\"DEF\",\"FittedRob\",\"NewCol\")])
\'data.frame\':   1000 obs. of  4 variables:
$ gvkey         : int  1004 1004          


        
3条回答
  •  旧时难觅i
    2021-01-27 07:24

    Use a bit of ave action, using the example data @Roland used:

    DF[ave(DF$b,DF$a, FUN=function(x) !any(x %in% c(2,3)))==1,]
    

    And an adaptation of Jan's nice answer:

    DF[!DF$a %in% unique(DF$a[DF$b %in% c(2,3)]) ,]
    

    Both giving:

      a  b
    5 b  5
    6 b 10
    9 b  5
    

提交回复
热议问题