Subsetting data.table set by date range in R

后端 未结 3 930
栀梦
栀梦 2020-12-05 02:54

I have a large dataset in data.table that I\'d like to subset by a date range. My data set looks like this:

testset <- data.table(date=as.Date(c(\"2013-07         


        
相关标签:
3条回答
  • 2020-12-05 03:14

    Why not:

    testset[date>="2013-08-02" & date<="2013-11-01"]
    
    0 讨论(0)
  • 2020-12-05 03:19

    You mentioned that you are subsetting, but its not clear whether you are using the subset fn in R.

    Type ?subset into the R console to see the details of the subset() function in R which 'returns a subset of vectors, matrices or data frames which meet conditions'. Then use part of the method that Troy posted above to choose the date range

    thisYear <- subset(testset, date > "2015-01-01" & date < "2015-12-31")
    
    0 讨论(0)
  • 2020-12-05 03:30

    See also:

    ?`%between%`
    

    Works like this:

    testset[date %between% c("2013-08-02", "2013-11-01")]
    
    0 讨论(0)
提交回复
热议问题