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.
Asked
Active
Viewed 54 times
-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
-
3Try something like `dat[grep('0$',dat$id),]` – agstudy Feb 22 '16 at 22:47
-
1Or if it's an integer: `ID %% 10 == 0` – Heroka Feb 22 '16 at 22:48
1 Answers
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