I would like to choose rows based on the subsets of their names, for example
If I have the following data:
data <- structure(c(91, 92, 108, 104, 87, 91, 91, 97, 81, 98),
.Names = c("fee-", "fi", "fo-", "fum-", "foo-", "foo1234-", "123foo-",
"fum-", "fum-", "fum-"))
how do I select the rows matching ‘foo’?
using grep() doesn’t work:
grep('foo', data)
returns:
integer(0)
what am I doing wrong? or, is there a better way?
Thanks!
You need to grep the names property of data, not the values property.
For your example, use
One other clean way to do this is using data frames.