Removing rows based on dependent conditions

前端 未结 1 781
眼角桃花
眼角桃花 2021-01-24 21:05

Removing rows on multiple parameters is not too diffcult, e.g.: data[!(data$fd==0 & data$cl==0),]

However, in the following dataframe:

d         


        
相关标签:
1条回答
  • 2021-01-24 21:42

    It's really better if you give a minimal example and complete desired output. It makes it much easier to test.

    From your description, i'm guessing this will work

    deleteable <- with(data, ave(fd, id, sq, p, FUN=function(x) all(x==0)))
    

    Here we use ave to look at the "fd" values grouping by "id","sq","p" and we check if they are all 0. If they are deleteable will equal 1; if not, 0; Then we can remove those rows with

    data[deleteable==0, ]
    
    0 讨论(0)
提交回复
热议问题