1

I have a dataset called salaries that have yearID as a column. I would like to specify the range of the year from 2010 to 2014. How could I do that in r ? I have tried this

df <- Salaries(yearID=c(2010,2011,2012,2013,2014))

also,

salar09-05<-Salaries(yearID=c(2010:2014))

and

sqldf("select * from salaries where yearID > 2009 and date < 2015")

neither one of them work.

Yahyaotaif
  • 1,943
  • 1
  • 15
  • 17

2 Answers2

2

We can use subset with %in%

subset(Salaries, yearID %in% 2010:2014) 
akrun
  • 874,273
  • 37
  • 540
  • 662
1

You need to use square brackets to subset.

df <- Salaries[Salaries$yearID %in% c(2010,2011,2012,2013,2014), ]

or

df <- Salaries[Salaries$yearID >= 2010 & Salaries$yearID <=2014, ] 

A single "=" is an assignment operator, not a test of equality.

Richard Telford
  • 9,558
  • 6
  • 38
  • 51