Filter data.frame rows by a logical condition

前端 未结 9 1573
爱一瞬间的悲伤
爱一瞬间的悲伤 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 05:48

    To select rows according to one 'cell_type' (e.g. 'hesc'), use ==:

    expr[expr$cell_type == "hesc", ]
    

    To select rows according to two or more different 'cell_type', (e.g. either 'hesc' or 'bj fibroblast'), use %in%:

    expr[expr$cell_type %in% c("hesc", "bj fibroblast"), ]
    

提交回复
热议问题