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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -