r - Subset data by condition -
if have data this:
a b c 1 gm1 100 2 dox 10 3 gm2 3 4 gm3 99 5 62 6 gmpn 30
how using r let data looks like:(only choose include "gm" data)
a b c 1 gm1 100 3 gm2 3 4 gm3 99
you can use grep
df1[grep('gm\\d+', df1$b),] # b c #1 1 gm1 100 #3 3 gm2 3 #4 4 gm3 99
or @colonelbeauvel mentioned
subset(df1, grepl('gm\\d+', b))
Comments
Post a Comment