Delete all rows coresponding to given ID

前端 未结 3 895
别跟我提以往
别跟我提以往 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条回答
  •  太阳男子
    2021-01-27 07:15

    set.seed(42)
    DF <- data.frame(a = sample(c("a", "b", "c"), 10, T), b = sample(1:10, 10, T))
    #    a  b
    # 1  c  5
    # 2  c  8
    # 3  a 10
    # 4  c  3
    # 5  b  5
    # 6  b 10
    # 7  c 10
    # 8  a  2
    # 9  b  5
    # 10 c  6
    
    
    library(plyr)
    res <- ddply(DF, .(a), transform, test = any(b %in% c(2, 3)))
    res[!res$test, 1:2]
    #   a  b
    # 3 b  5
    # 4 b 10
    # 5 b  5
    

提交回复
热议问题