This function takes the
open_hours variable in an already-read Core file (stored as a
data.table) and expands it to seven
list-type columns, where the elements of the list in each row are a set of vectors for opening/closing times, in military time format (1:30PM = 13.5). So an observation of
c(8,10,12,14) would be a business that opens at 8, closes at 10, opens again at noon, and closes again at 2PM on that day. Options are available to produce long instead of wide expansions as well.
data.table containing the
open_hours column (or an object that can be coerced to a
'wide' (seven new
list-columns, one for each day),
'long' (turn each row into seven rows, then two new columns: one for day-of-week and one
list-column with opening/closing times), or
'long' but then also break the single list-column out into a set of numeric start/end columns). Note that for
'long-expand', many locations have more than one set of open/close hours per day, so there will be more than one open/close column each.
A character variable with the name of the
format = 'wide', the name stub for the column names, by default
'open_hours' to get
'open_hoursMonday', etc.. For
format='long', a two-element vector (by default
c('weekday','open_hours')) with the name of the column indicating the day, and the
list-column with the open hours information in it. For
format = 'long-expand', a three-element vector with the weekday column, the name stub for "opening hour" and the name stub for "closing hour" (with numbers 1, 2, 3, etc. appended afterwards), by default
Drop any rows with a missing
Convert hour strings like
'15:30' to numbers like
15.5. This does slow down the function.
A character vector of the days to keep. Cutting down here can save some time/memory especially if you are not going
format = 'wide'.
Returns the same
data.table but with the new columns/rows added. May change the order of the data.