Reputation: 15298
I'm using lubridate
and I have a basic question. How can I choose all the values of a dataset that occur before a certain date?
For example, if I want to subset the values such that everything that occurs before July 8, what syntax do I use? I could not figure this out from reading the docs, or looking at the vignette example.
My dataframe looks like this:
> str(mydata)
'data.frame': 1434 obs. of 7 variables:
$ name : chr "0" "0" "0" "0" ...
$ value : num 25 100 50 150 5 100 99 500 100 100 ...
$ timestamp: POSIXct, format: "2014-06-27 10:49:20" ...
Upvotes: 2
Views: 3085
Reputation: 3615
You don't actually need lubridate
I don't think. The following should work:
mydata[mydata$timestamp < as.POSIXct("2014-07-08"), ]
A version with lubridate
would be similar:
mydata[mydata$timestamp < ymd("2014-07-08"), ]
Upvotes: 1