Reputation: 31
How can I subtract data by time using lubridate package???
I'm working with a dataframe in R and I want to subtract a subset by time after "2016-06-01".
My data time format is "yyyy-mm-dd" and its class is Date.
I'm trying to subtract using lubridate package like:
data[ymd(data$date)>='2016-06-01']
but it doesn't work at all.
Upvotes: 1
Views: 908
Reputation: 1349
To subset a matrix or data frame in R you have to use two arguments within single brackets []
, separated by a comma. The first argument specifies the rows, and the second specifies the columns, stylized as
data[ROWS, COLS]
So to keep the rows matching your predicate, use
data[ymd(data$date) >= "2016-06-01", ]
Upvotes: 2