Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: R: find largest interval in dates with condition

Alexey Ferapontov:

I have a data frame with date and price. For some dates, price is NA. I'm trying to find the largest interval in dates between "last" (in a continuous sequence) NA price and last non-NA price. I'm completely lost - I suspect difftime needs to be used but I cannot come up with a condition for this.

E.g.:


DF = structure(list(rollup_date = c("2017-05-01 00:00:00", "2017-05-02 00:00:00",
"2017-05-03 00:00:00", "2017-05-04 00:00:00", "2017-05-05 00:00:00",
"2017-05-06 00:00:00", "2017-05-07 00:00:00", "2017-05-08 00:00:00",
"2017-05-09 00:00:00", "2017-05-10 00:00:00", "2017-05-11 00:00:00",
"2017-05-12 00:00:00", "2017-05-13 00:00:00", "2017-05-14 00:00:00",
"2017-05-15 00:00:00"), RegularPrice = c(6.47, 6.47, 6.47, 6.47,
NA, NA, NA, NA, NA, NA, NA, 6.47, NA, 6.47, 6.47)), .Names = c("rollup_date",
"RegularPrice"), row.names = 145624:145638, class = "data.frame")

So, outputs here are 7 days (5/11 - 5/04) and 1 day (5/13 - 5/12). All solutions can be stored and then I just pick largest.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: R: find largest interval in dates with condition

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×