-1

I am trying to make a subset of my data table (counties) consisting of rows where the id number ends in zero. I have tried using grep and %like% but these are specific to the entire id value and not just the last integer value.

The highlighted values are examples of what I would want to extract

Heroka
  • 12,889
  • 1
  • 28
  • 38
kknapp14
  • 7
  • 1
  • Hi, welcome to SO. Please consider reading up on [ask] and how to produce a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). It makes it easier for others to help you. This includes not posting data as an image, and including (even if it didn't work) the code you tried. – Heroka Feb 22 '16 at 22:44
  • 3
    Try something like `dat[grep('0$',dat$id),]` – agstudy Feb 22 '16 at 22:47
  • 1
    Or if it's an integer: `ID %% 10 == 0` – Heroka Feb 22 '16 at 22:48

1 Answers1

1

Use the sqldf package:

library(sqldf)
sqldf("select * from dat where Id like '%0'")

OR the data.table package: As suggested by Frank

dat[id %like% "0$"]
CuriousBeing
  • 1,592
  • 14
  • 34