Skip to content
Prev 174405 / 398506 Next

Subsetting data where the condition is that the value of some column contains some substring

If you use Jim's example and use grep() with ordinary and and then  
negative indexing, you get these results:

 > x[grep("her", x$input),]
                 input output corpusFreq pvolOT pvolRatioOT
2 donate(her,thebook)      P       48.7  68928   0.1899471
6        give(her,it)      P      100.0 157248   0.4333333
8   give(her,thebook)      P        5.7  65232   0.1797619
9      donate(her,it)      P      100.0 152064   0.4190476

 > x[-grep("her", x$input),]
                             input output corpusFreq pvolOT pvolRatioOT
1       give(mysister,theoldbook)      P       47.0  56016   0.1543651
3          give(mysister,thebook)      P       73.4  80136   0.2208333
4     donate(mysister,theoldbook)      P       79.0  57024   0.1571429
5               give(mysister,it)      P      100.0 132408   0.3648810
7             donate(mysister,it)      P      100.0 130720   0.3602293
10   give(mylittlesister,thebook)      P       91.8 112032   0.3087302
11 donate(mylittlesister,thebook)      P       98.4 114048   0.3142857
12       donate(mysister,thebook)      P       94.4  82800   0.2281746