Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter on date and hour onward?

Tags:

date

r

dplyr

I've a simple data frame, and I need to filter every column from date: 2020-04-08 and hour 17 onwoards.

I've this:

bcp_desde_las_5 <- bcp %>%
                   filter(date == "2020-04-08" & hour == 17)

But it only returns data from that date and hour, not onwoards data as desired.

UPDATE:

The filter for hour should only apply to the first date: 2020-04-08. It means that for that day I only need the data from 17 h to midnight. But for every other date, I need every hour of the date.

like image 803
Omar Gonzales Avatar asked Dec 11 '25 20:12

Omar Gonzales


2 Answers

If the intention is to get the 'hour' greater than or equal to 17, then change the == to >=

library(dplyr)
bcp %>%
      filter((date == as.Date("2020-04-08") & hour >= 17)| 
             (date != as.Date("2020-04-08")))
like image 179
akrun Avatar answered Dec 13 '25 09:12

akrun


In order to get every time point from 2020-04-08 and hour 17 onwards, you can use

library(dplyr)
bcp %>% 
  filter((date == as.Date("2020-04-08") & hour >= 17) | date > as.Date("2020-04-08"))
like image 30
Ric S Avatar answered Dec 13 '25 10:12

Ric S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!