You are looking for subset
if your data is called mydata
newdata <- subset(mydata, city < 1e6)
Or you could use [
, which is programatically safer
newdata <- mydata[mydata$city < 1e6]
For more than one condition use &
or |
where approriate
You could also use the sqldf
package to use sql
library(sqldf)newdata <- sqldf('select * from mydata where city > 1e6')
Or you could use data.table
which makes the syntax easier for [
(as well as being memory efficient)
library(data.table)mydatatable <- data.table(mydata)newdata <- mydatatable[city > 1e6]