Filter data.frame rows by a logical condition

前端 未结 9 1391
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-21 05:43

I want to filter rows from a data.frame based on a logical condition. Let\'s suppose that I have data frame like

   expr_value     cell_type
1           


        
9条回答
  •  渐次进展
    2020-11-21 06:00

    No one seems to have included the which function. It can also prove useful for filtering.

    expr[which(expr$cell == 'hesc'),]
    

    This will also handle NAs and drop them from the resulting dataframe.

    Running this on a 9840 by 24 dataframe 50000 times, it seems like the which method has a 60% faster run time than the %in% method.

提交回复
热议问题