Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

filter_time to specific time window every day? #46

Closed
ericpgreen opened this issue Feb 11, 2018 · 2 comments
Closed

filter_time to specific time window every day? #46

ericpgreen opened this issue Feb 11, 2018 · 2 comments

Comments

@ericpgreen
Copy link

Great stuff with tibbletime. How can I use filter_time() to get a specific time window each day? For instance, just the hours of 02:00 to 04:00?

example <- create_series('2013-01-01'~'2013-01-02', period = 'hour')
@ericpgreen
Copy link
Author

this works, but not sure how to accomplish with filter_time

example %>%
  filter(hour(date)>2 & hour(date)<=4)

# A time tibble: 4 x 1
# Index: date
  date               
  <dttm>             
1 2013-01-01 03:00:00
2 2013-01-01 04:00:00
3 2013-01-02 03:00:00
4 2013-01-02 04:00:00

@DavisVaughan
Copy link
Collaborator

DavisVaughan commented Mar 22, 2018

Great question. The simple answer is, you can't! At least not yet.

I've been thinking about this for awhile, and have termed them "continuous" vs "disjoint" filters. Continuous range filters are available (entire months / entire days where there is no break between days), but disjoint are not.

I've been toying with the idea of "wildcard filters" in filter_time() but haven't gotten around to implementing because I dont know how useful it would be. But it would solve your problem. It might look something like:

example %>% time_filter("?-?-? 03" ~ "?-?-? 04")

Its strange looking, but would essentially be saying "for every day, filter only the rows with hours from 3-4"

Other applications would be:

example %>% time_filter("?-?-12" ~ "?-?-15")

The 12th-15th days of every month in your series.

But again, what you have already using lubridate is pretty easy too, which is another reason it hasnt happened yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants