I am new to R and can\'t get to grips with this concept. Suppose I have a table loaded called \"places\" with 3 say columns - city, population and average summer temperature
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]