Filter data.frame rows by a logical condition

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”), ]

Why is `[` better than `subset`?

This question was answered in well in the comments by @James, pointing to an excellent explanation by Hadley Wickham of the dangers of subset (and functions like it) [here]. Go read it! It’s a somewhat long read, so it may be helpful to record here the example that Hadley uses that most directly addresses the … Read more

tech