I have a dataset with many rows of multiple dates, and for each date, data associated with multiple times for that day. I want to filter down to one particular time of day (the same time each day, which is stock market open, EST) for each day in the dataset.
Example Problem:
dat1 <- tibble(
DateTime = rep(as.POSIXct(c("2019-02-21 09:30:00",
"2019-02-21 16:30:00",
"2019-02-22 09:30:00",
"2019-02-22 16:30:00",
"2019-02-25 09:30:00",
"2019-02-25 16:30:00")), each=3),
Ticker = c("AAPL", "AAPL", "AAPL", "AAPL", "AAPL", "AAPL",
"ABC", "ABC", "ABC", "ABC", "ABC", "ABC",
"ADBE", "ADBE", "ADBE", "ADBE", "ADBE", "ADBE"),
Thirtymin = c(11000000,12000000,11500000,12500000,13000000,13400000,
30000,35000,33000,80000,280000,250000,
2000,2100,2200,2340,2300,2350),
Tgt_Shares = c(2500,2600,2400,2350,2600,2700,
1000,2000,3000,2000,1500,2000,
100,350,600,450,390,475)
)
I could, of course, use the following...
dat2 <- dat1 %>%
filter (
DateTime == "2019-02-21 09:30:00" |
DateTime == "2019-02-22 09:30:00" |
DateTime == "2019-02-25 09:30:00"
)
...but the actual dataset is too big for this approach -- though in this simple case, it is the desired results.
I see lots of posts on date/times, of course, but many are not in respect to dplyr or even R, and I haven't seen any that filter a particular time for each of several trading (non-consecutive) days.
I'm sure there is a simple answer, but I'm missing it!