Take the datetime variable in a data frame and map this to a variable of a higher interval. The mapping is added to the data frame in a new variable. After applying thicken the user can aggregate the other variables in the data frame to the higher interval, for instance using dplyr.

thicken(x, interval, colname = NULL, rounding = c("down", "up"),
  by = NULL, start_val = NULL, drop = FALSE, ties_to_earlier = FALSE)

Arguments

x

A data frame containing at least one datetime variable of class Date, POSIXct or POSIXlt.

interval

The interval of the added datetime variable. Any character string that would be accepted by seq.Date or seq.POSIXt. It can only be higher than the interval and step size of the input data.

colname

The column name of the added variable. If NULL it will be the name of the original datetime variable with the interval name added to it (including the unit), separated by underscores.

rounding

Should a value in the input datetime variable be mapped to the closest value that is lower (down) or that is higher (up) than itself.

by

Only needs to be specified when x contains multiple variables of class Date, POSIXct or POSIXlt. Indicates which to use for thickening.

start_val

By default the first instance of interval that is lower than the lowest value of the input datetime variable, with all time units on default value. Specify start_val as an offset if you want the range to be nonstandard.

drop

Should the original datetime variable be dropped from the returned data frame? Defaults to FALSE.

ties_to_earlier

By default when the original datetime observations is tied with a value in the added datetime variable, it is assigned to the current value when rounding is down or to the next value when rounding is up. When TRUE the ties will be assigned to the previous observation of the new variable instead.

Value

The data frame x with the variable added to it.

Details

When the datetime variable contains missing values, they are left in place in the dataframe. The added column with the new datetime variable, will have a missing values for these rows as well.

See vignette("padr") for more information on thicken. See vignette("padr_implementation") for detailed information on daylight savings time, different timezones, and the implementation of thicken.

Examples

x_hour <- seq(lubridate::ymd_hms('20160302 000000'), by = 'hour', length.out = 200) some_df <- data.frame(x_hour = x_hour) thicken(some_df, 'week')
#> x_hour x_hour_week #> 1 2016-03-02 00:00:00 2016-02-28 #> 2 2016-03-02 01:00:00 2016-02-28 #> 3 2016-03-02 02:00:00 2016-02-28 #> 4 2016-03-02 03:00:00 2016-02-28 #> 5 2016-03-02 04:00:00 2016-02-28 #> 6 2016-03-02 05:00:00 2016-02-28 #> 7 2016-03-02 06:00:00 2016-02-28 #> 8 2016-03-02 07:00:00 2016-02-28 #> 9 2016-03-02 08:00:00 2016-02-28 #> 10 2016-03-02 09:00:00 2016-02-28 #> 11 2016-03-02 10:00:00 2016-02-28 #> 12 2016-03-02 11:00:00 2016-02-28 #> 13 2016-03-02 12:00:00 2016-02-28 #> 14 2016-03-02 13:00:00 2016-02-28 #> 15 2016-03-02 14:00:00 2016-02-28 #> 16 2016-03-02 15:00:00 2016-02-28 #> 17 2016-03-02 16:00:00 2016-02-28 #> 18 2016-03-02 17:00:00 2016-02-28 #> 19 2016-03-02 18:00:00 2016-02-28 #> 20 2016-03-02 19:00:00 2016-02-28 #> 21 2016-03-02 20:00:00 2016-02-28 #> 22 2016-03-02 21:00:00 2016-02-28 #> 23 2016-03-02 22:00:00 2016-02-28 #> 24 2016-03-02 23:00:00 2016-02-28 #> 25 2016-03-03 00:00:00 2016-02-28 #> 26 2016-03-03 01:00:00 2016-02-28 #> 27 2016-03-03 02:00:00 2016-02-28 #> 28 2016-03-03 03:00:00 2016-02-28 #> 29 2016-03-03 04:00:00 2016-02-28 #> 30 2016-03-03 05:00:00 2016-02-28 #> 31 2016-03-03 06:00:00 2016-02-28 #> 32 2016-03-03 07:00:00 2016-02-28 #> 33 2016-03-03 08:00:00 2016-02-28 #> 34 2016-03-03 09:00:00 2016-02-28 #> 35 2016-03-03 10:00:00 2016-02-28 #> 36 2016-03-03 11:00:00 2016-02-28 #> 37 2016-03-03 12:00:00 2016-02-28 #> 38 2016-03-03 13:00:00 2016-02-28 #> 39 2016-03-03 14:00:00 2016-02-28 #> 40 2016-03-03 15:00:00 2016-02-28 #> 41 2016-03-03 16:00:00 2016-02-28 #> 42 2016-03-03 17:00:00 2016-02-28 #> 43 2016-03-03 18:00:00 2016-02-28 #> 44 2016-03-03 19:00:00 2016-02-28 #> 45 2016-03-03 20:00:00 2016-02-28 #> 46 2016-03-03 21:00:00 2016-02-28 #> 47 2016-03-03 22:00:00 2016-02-28 #> 48 2016-03-03 23:00:00 2016-02-28 #> 49 2016-03-04 00:00:00 2016-02-28 #> 50 2016-03-04 01:00:00 2016-02-28 #> 51 2016-03-04 02:00:00 2016-02-28 #> 52 2016-03-04 03:00:00 2016-02-28 #> 53 2016-03-04 04:00:00 2016-02-28 #> 54 2016-03-04 05:00:00 2016-02-28 #> 55 2016-03-04 06:00:00 2016-02-28 #> 56 2016-03-04 07:00:00 2016-02-28 #> 57 2016-03-04 08:00:00 2016-02-28 #> 58 2016-03-04 09:00:00 2016-02-28 #> 59 2016-03-04 10:00:00 2016-02-28 #> 60 2016-03-04 11:00:00 2016-02-28 #> 61 2016-03-04 12:00:00 2016-02-28 #> 62 2016-03-04 13:00:00 2016-02-28 #> 63 2016-03-04 14:00:00 2016-02-28 #> 64 2016-03-04 15:00:00 2016-02-28 #> 65 2016-03-04 16:00:00 2016-02-28 #> 66 2016-03-04 17:00:00 2016-02-28 #> 67 2016-03-04 18:00:00 2016-02-28 #> 68 2016-03-04 19:00:00 2016-02-28 #> 69 2016-03-04 20:00:00 2016-02-28 #> 70 2016-03-04 21:00:00 2016-02-28 #> 71 2016-03-04 22:00:00 2016-02-28 #> 72 2016-03-04 23:00:00 2016-02-28 #> 73 2016-03-05 00:00:00 2016-02-28 #> 74 2016-03-05 01:00:00 2016-02-28 #> 75 2016-03-05 02:00:00 2016-02-28 #> 76 2016-03-05 03:00:00 2016-02-28 #> 77 2016-03-05 04:00:00 2016-02-28 #> 78 2016-03-05 05:00:00 2016-02-28 #> 79 2016-03-05 06:00:00 2016-02-28 #> 80 2016-03-05 07:00:00 2016-02-28 #> 81 2016-03-05 08:00:00 2016-02-28 #> 82 2016-03-05 09:00:00 2016-02-28 #> 83 2016-03-05 10:00:00 2016-02-28 #> 84 2016-03-05 11:00:00 2016-02-28 #> 85 2016-03-05 12:00:00 2016-02-28 #> 86 2016-03-05 13:00:00 2016-02-28 #> 87 2016-03-05 14:00:00 2016-02-28 #> 88 2016-03-05 15:00:00 2016-02-28 #> 89 2016-03-05 16:00:00 2016-02-28 #> 90 2016-03-05 17:00:00 2016-02-28 #> 91 2016-03-05 18:00:00 2016-02-28 #> 92 2016-03-05 19:00:00 2016-02-28 #> 93 2016-03-05 20:00:00 2016-02-28 #> 94 2016-03-05 21:00:00 2016-02-28 #> 95 2016-03-05 22:00:00 2016-02-28 #> 96 2016-03-05 23:00:00 2016-02-28 #> 97 2016-03-06 00:00:00 2016-03-06 #> 98 2016-03-06 01:00:00 2016-03-06 #> 99 2016-03-06 02:00:00 2016-03-06 #> 100 2016-03-06 03:00:00 2016-03-06 #> 101 2016-03-06 04:00:00 2016-03-06 #> 102 2016-03-06 05:00:00 2016-03-06 #> 103 2016-03-06 06:00:00 2016-03-06 #> 104 2016-03-06 07:00:00 2016-03-06 #> 105 2016-03-06 08:00:00 2016-03-06 #> 106 2016-03-06 09:00:00 2016-03-06 #> 107 2016-03-06 10:00:00 2016-03-06 #> 108 2016-03-06 11:00:00 2016-03-06 #> 109 2016-03-06 12:00:00 2016-03-06 #> 110 2016-03-06 13:00:00 2016-03-06 #> 111 2016-03-06 14:00:00 2016-03-06 #> 112 2016-03-06 15:00:00 2016-03-06 #> 113 2016-03-06 16:00:00 2016-03-06 #> 114 2016-03-06 17:00:00 2016-03-06 #> 115 2016-03-06 18:00:00 2016-03-06 #> 116 2016-03-06 19:00:00 2016-03-06 #> 117 2016-03-06 20:00:00 2016-03-06 #> 118 2016-03-06 21:00:00 2016-03-06 #> 119 2016-03-06 22:00:00 2016-03-06 #> 120 2016-03-06 23:00:00 2016-03-06 #> 121 2016-03-07 00:00:00 2016-03-06 #> 122 2016-03-07 01:00:00 2016-03-06 #> 123 2016-03-07 02:00:00 2016-03-06 #> 124 2016-03-07 03:00:00 2016-03-06 #> 125 2016-03-07 04:00:00 2016-03-06 #> 126 2016-03-07 05:00:00 2016-03-06 #> 127 2016-03-07 06:00:00 2016-03-06 #> 128 2016-03-07 07:00:00 2016-03-06 #> 129 2016-03-07 08:00:00 2016-03-06 #> 130 2016-03-07 09:00:00 2016-03-06 #> 131 2016-03-07 10:00:00 2016-03-06 #> 132 2016-03-07 11:00:00 2016-03-06 #> 133 2016-03-07 12:00:00 2016-03-06 #> 134 2016-03-07 13:00:00 2016-03-06 #> 135 2016-03-07 14:00:00 2016-03-06 #> 136 2016-03-07 15:00:00 2016-03-06 #> 137 2016-03-07 16:00:00 2016-03-06 #> 138 2016-03-07 17:00:00 2016-03-06 #> 139 2016-03-07 18:00:00 2016-03-06 #> 140 2016-03-07 19:00:00 2016-03-06 #> 141 2016-03-07 20:00:00 2016-03-06 #> 142 2016-03-07 21:00:00 2016-03-06 #> 143 2016-03-07 22:00:00 2016-03-06 #> 144 2016-03-07 23:00:00 2016-03-06 #> 145 2016-03-08 00:00:00 2016-03-06 #> 146 2016-03-08 01:00:00 2016-03-06 #> 147 2016-03-08 02:00:00 2016-03-06 #> 148 2016-03-08 03:00:00 2016-03-06 #> 149 2016-03-08 04:00:00 2016-03-06 #> 150 2016-03-08 05:00:00 2016-03-06 #> 151 2016-03-08 06:00:00 2016-03-06 #> 152 2016-03-08 07:00:00 2016-03-06 #> 153 2016-03-08 08:00:00 2016-03-06 #> 154 2016-03-08 09:00:00 2016-03-06 #> 155 2016-03-08 10:00:00 2016-03-06 #> 156 2016-03-08 11:00:00 2016-03-06 #> 157 2016-03-08 12:00:00 2016-03-06 #> 158 2016-03-08 13:00:00 2016-03-06 #> 159 2016-03-08 14:00:00 2016-03-06 #> 160 2016-03-08 15:00:00 2016-03-06 #> 161 2016-03-08 16:00:00 2016-03-06 #> 162 2016-03-08 17:00:00 2016-03-06 #> 163 2016-03-08 18:00:00 2016-03-06 #> 164 2016-03-08 19:00:00 2016-03-06 #> 165 2016-03-08 20:00:00 2016-03-06 #> 166 2016-03-08 21:00:00 2016-03-06 #> 167 2016-03-08 22:00:00 2016-03-06 #> 168 2016-03-08 23:00:00 2016-03-06 #> 169 2016-03-09 00:00:00 2016-03-06 #> 170 2016-03-09 01:00:00 2016-03-06 #> 171 2016-03-09 02:00:00 2016-03-06 #> 172 2016-03-09 03:00:00 2016-03-06 #> 173 2016-03-09 04:00:00 2016-03-06 #> 174 2016-03-09 05:00:00 2016-03-06 #> 175 2016-03-09 06:00:00 2016-03-06 #> 176 2016-03-09 07:00:00 2016-03-06 #> 177 2016-03-09 08:00:00 2016-03-06 #> 178 2016-03-09 09:00:00 2016-03-06 #> 179 2016-03-09 10:00:00 2016-03-06 #> 180 2016-03-09 11:00:00 2016-03-06 #> 181 2016-03-09 12:00:00 2016-03-06 #> 182 2016-03-09 13:00:00 2016-03-06 #> 183 2016-03-09 14:00:00 2016-03-06 #> 184 2016-03-09 15:00:00 2016-03-06 #> 185 2016-03-09 16:00:00 2016-03-06 #> 186 2016-03-09 17:00:00 2016-03-06 #> 187 2016-03-09 18:00:00 2016-03-06 #> 188 2016-03-09 19:00:00 2016-03-06 #> 189 2016-03-09 20:00:00 2016-03-06 #> 190 2016-03-09 21:00:00 2016-03-06 #> 191 2016-03-09 22:00:00 2016-03-06 #> 192 2016-03-09 23:00:00 2016-03-06 #> 193 2016-03-10 00:00:00 2016-03-06 #> 194 2016-03-10 01:00:00 2016-03-06 #> 195 2016-03-10 02:00:00 2016-03-06 #> 196 2016-03-10 03:00:00 2016-03-06 #> 197 2016-03-10 04:00:00 2016-03-06 #> 198 2016-03-10 05:00:00 2016-03-06 #> 199 2016-03-10 06:00:00 2016-03-06 #> 200 2016-03-10 07:00:00 2016-03-06
thicken(some_df, 'month')
#> x_hour x_hour_month #> 1 2016-03-02 00:00:00 2016-03-01 #> 2 2016-03-02 01:00:00 2016-03-01 #> 3 2016-03-02 02:00:00 2016-03-01 #> 4 2016-03-02 03:00:00 2016-03-01 #> 5 2016-03-02 04:00:00 2016-03-01 #> 6 2016-03-02 05:00:00 2016-03-01 #> 7 2016-03-02 06:00:00 2016-03-01 #> 8 2016-03-02 07:00:00 2016-03-01 #> 9 2016-03-02 08:00:00 2016-03-01 #> 10 2016-03-02 09:00:00 2016-03-01 #> 11 2016-03-02 10:00:00 2016-03-01 #> 12 2016-03-02 11:00:00 2016-03-01 #> 13 2016-03-02 12:00:00 2016-03-01 #> 14 2016-03-02 13:00:00 2016-03-01 #> 15 2016-03-02 14:00:00 2016-03-01 #> 16 2016-03-02 15:00:00 2016-03-01 #> 17 2016-03-02 16:00:00 2016-03-01 #> 18 2016-03-02 17:00:00 2016-03-01 #> 19 2016-03-02 18:00:00 2016-03-01 #> 20 2016-03-02 19:00:00 2016-03-01 #> 21 2016-03-02 20:00:00 2016-03-01 #> 22 2016-03-02 21:00:00 2016-03-01 #> 23 2016-03-02 22:00:00 2016-03-01 #> 24 2016-03-02 23:00:00 2016-03-01 #> 25 2016-03-03 00:00:00 2016-03-01 #> 26 2016-03-03 01:00:00 2016-03-01 #> 27 2016-03-03 02:00:00 2016-03-01 #> 28 2016-03-03 03:00:00 2016-03-01 #> 29 2016-03-03 04:00:00 2016-03-01 #> 30 2016-03-03 05:00:00 2016-03-01 #> 31 2016-03-03 06:00:00 2016-03-01 #> 32 2016-03-03 07:00:00 2016-03-01 #> 33 2016-03-03 08:00:00 2016-03-01 #> 34 2016-03-03 09:00:00 2016-03-01 #> 35 2016-03-03 10:00:00 2016-03-01 #> 36 2016-03-03 11:00:00 2016-03-01 #> 37 2016-03-03 12:00:00 2016-03-01 #> 38 2016-03-03 13:00:00 2016-03-01 #> 39 2016-03-03 14:00:00 2016-03-01 #> 40 2016-03-03 15:00:00 2016-03-01 #> 41 2016-03-03 16:00:00 2016-03-01 #> 42 2016-03-03 17:00:00 2016-03-01 #> 43 2016-03-03 18:00:00 2016-03-01 #> 44 2016-03-03 19:00:00 2016-03-01 #> 45 2016-03-03 20:00:00 2016-03-01 #> 46 2016-03-03 21:00:00 2016-03-01 #> 47 2016-03-03 22:00:00 2016-03-01 #> 48 2016-03-03 23:00:00 2016-03-01 #> 49 2016-03-04 00:00:00 2016-03-01 #> 50 2016-03-04 01:00:00 2016-03-01 #> 51 2016-03-04 02:00:00 2016-03-01 #> 52 2016-03-04 03:00:00 2016-03-01 #> 53 2016-03-04 04:00:00 2016-03-01 #> 54 2016-03-04 05:00:00 2016-03-01 #> 55 2016-03-04 06:00:00 2016-03-01 #> 56 2016-03-04 07:00:00 2016-03-01 #> 57 2016-03-04 08:00:00 2016-03-01 #> 58 2016-03-04 09:00:00 2016-03-01 #> 59 2016-03-04 10:00:00 2016-03-01 #> 60 2016-03-04 11:00:00 2016-03-01 #> 61 2016-03-04 12:00:00 2016-03-01 #> 62 2016-03-04 13:00:00 2016-03-01 #> 63 2016-03-04 14:00:00 2016-03-01 #> 64 2016-03-04 15:00:00 2016-03-01 #> 65 2016-03-04 16:00:00 2016-03-01 #> 66 2016-03-04 17:00:00 2016-03-01 #> 67 2016-03-04 18:00:00 2016-03-01 #> 68 2016-03-04 19:00:00 2016-03-01 #> 69 2016-03-04 20:00:00 2016-03-01 #> 70 2016-03-04 21:00:00 2016-03-01 #> 71 2016-03-04 22:00:00 2016-03-01 #> 72 2016-03-04 23:00:00 2016-03-01 #> 73 2016-03-05 00:00:00 2016-03-01 #> 74 2016-03-05 01:00:00 2016-03-01 #> 75 2016-03-05 02:00:00 2016-03-01 #> 76 2016-03-05 03:00:00 2016-03-01 #> 77 2016-03-05 04:00:00 2016-03-01 #> 78 2016-03-05 05:00:00 2016-03-01 #> 79 2016-03-05 06:00:00 2016-03-01 #> 80 2016-03-05 07:00:00 2016-03-01 #> 81 2016-03-05 08:00:00 2016-03-01 #> 82 2016-03-05 09:00:00 2016-03-01 #> 83 2016-03-05 10:00:00 2016-03-01 #> 84 2016-03-05 11:00:00 2016-03-01 #> 85 2016-03-05 12:00:00 2016-03-01 #> 86 2016-03-05 13:00:00 2016-03-01 #> 87 2016-03-05 14:00:00 2016-03-01 #> 88 2016-03-05 15:00:00 2016-03-01 #> 89 2016-03-05 16:00:00 2016-03-01 #> 90 2016-03-05 17:00:00 2016-03-01 #> 91 2016-03-05 18:00:00 2016-03-01 #> 92 2016-03-05 19:00:00 2016-03-01 #> 93 2016-03-05 20:00:00 2016-03-01 #> 94 2016-03-05 21:00:00 2016-03-01 #> 95 2016-03-05 22:00:00 2016-03-01 #> 96 2016-03-05 23:00:00 2016-03-01 #> 97 2016-03-06 00:00:00 2016-03-01 #> 98 2016-03-06 01:00:00 2016-03-01 #> 99 2016-03-06 02:00:00 2016-03-01 #> 100 2016-03-06 03:00:00 2016-03-01 #> 101 2016-03-06 04:00:00 2016-03-01 #> 102 2016-03-06 05:00:00 2016-03-01 #> 103 2016-03-06 06:00:00 2016-03-01 #> 104 2016-03-06 07:00:00 2016-03-01 #> 105 2016-03-06 08:00:00 2016-03-01 #> 106 2016-03-06 09:00:00 2016-03-01 #> 107 2016-03-06 10:00:00 2016-03-01 #> 108 2016-03-06 11:00:00 2016-03-01 #> 109 2016-03-06 12:00:00 2016-03-01 #> 110 2016-03-06 13:00:00 2016-03-01 #> 111 2016-03-06 14:00:00 2016-03-01 #> 112 2016-03-06 15:00:00 2016-03-01 #> 113 2016-03-06 16:00:00 2016-03-01 #> 114 2016-03-06 17:00:00 2016-03-01 #> 115 2016-03-06 18:00:00 2016-03-01 #> 116 2016-03-06 19:00:00 2016-03-01 #> 117 2016-03-06 20:00:00 2016-03-01 #> 118 2016-03-06 21:00:00 2016-03-01 #> 119 2016-03-06 22:00:00 2016-03-01 #> 120 2016-03-06 23:00:00 2016-03-01 #> 121 2016-03-07 00:00:00 2016-03-01 #> 122 2016-03-07 01:00:00 2016-03-01 #> 123 2016-03-07 02:00:00 2016-03-01 #> 124 2016-03-07 03:00:00 2016-03-01 #> 125 2016-03-07 04:00:00 2016-03-01 #> 126 2016-03-07 05:00:00 2016-03-01 #> 127 2016-03-07 06:00:00 2016-03-01 #> 128 2016-03-07 07:00:00 2016-03-01 #> 129 2016-03-07 08:00:00 2016-03-01 #> 130 2016-03-07 09:00:00 2016-03-01 #> 131 2016-03-07 10:00:00 2016-03-01 #> 132 2016-03-07 11:00:00 2016-03-01 #> 133 2016-03-07 12:00:00 2016-03-01 #> 134 2016-03-07 13:00:00 2016-03-01 #> 135 2016-03-07 14:00:00 2016-03-01 #> 136 2016-03-07 15:00:00 2016-03-01 #> 137 2016-03-07 16:00:00 2016-03-01 #> 138 2016-03-07 17:00:00 2016-03-01 #> 139 2016-03-07 18:00:00 2016-03-01 #> 140 2016-03-07 19:00:00 2016-03-01 #> 141 2016-03-07 20:00:00 2016-03-01 #> 142 2016-03-07 21:00:00 2016-03-01 #> 143 2016-03-07 22:00:00 2016-03-01 #> 144 2016-03-07 23:00:00 2016-03-01 #> 145 2016-03-08 00:00:00 2016-03-01 #> 146 2016-03-08 01:00:00 2016-03-01 #> 147 2016-03-08 02:00:00 2016-03-01 #> 148 2016-03-08 03:00:00 2016-03-01 #> 149 2016-03-08 04:00:00 2016-03-01 #> 150 2016-03-08 05:00:00 2016-03-01 #> 151 2016-03-08 06:00:00 2016-03-01 #> 152 2016-03-08 07:00:00 2016-03-01 #> 153 2016-03-08 08:00:00 2016-03-01 #> 154 2016-03-08 09:00:00 2016-03-01 #> 155 2016-03-08 10:00:00 2016-03-01 #> 156 2016-03-08 11:00:00 2016-03-01 #> 157 2016-03-08 12:00:00 2016-03-01 #> 158 2016-03-08 13:00:00 2016-03-01 #> 159 2016-03-08 14:00:00 2016-03-01 #> 160 2016-03-08 15:00:00 2016-03-01 #> 161 2016-03-08 16:00:00 2016-03-01 #> 162 2016-03-08 17:00:00 2016-03-01 #> 163 2016-03-08 18:00:00 2016-03-01 #> 164 2016-03-08 19:00:00 2016-03-01 #> 165 2016-03-08 20:00:00 2016-03-01 #> 166 2016-03-08 21:00:00 2016-03-01 #> 167 2016-03-08 22:00:00 2016-03-01 #> 168 2016-03-08 23:00:00 2016-03-01 #> 169 2016-03-09 00:00:00 2016-03-01 #> 170 2016-03-09 01:00:00 2016-03-01 #> 171 2016-03-09 02:00:00 2016-03-01 #> 172 2016-03-09 03:00:00 2016-03-01 #> 173 2016-03-09 04:00:00 2016-03-01 #> 174 2016-03-09 05:00:00 2016-03-01 #> 175 2016-03-09 06:00:00 2016-03-01 #> 176 2016-03-09 07:00:00 2016-03-01 #> 177 2016-03-09 08:00:00 2016-03-01 #> 178 2016-03-09 09:00:00 2016-03-01 #> 179 2016-03-09 10:00:00 2016-03-01 #> 180 2016-03-09 11:00:00 2016-03-01 #> 181 2016-03-09 12:00:00 2016-03-01 #> 182 2016-03-09 13:00:00 2016-03-01 #> 183 2016-03-09 14:00:00 2016-03-01 #> 184 2016-03-09 15:00:00 2016-03-01 #> 185 2016-03-09 16:00:00 2016-03-01 #> 186 2016-03-09 17:00:00 2016-03-01 #> 187 2016-03-09 18:00:00 2016-03-01 #> 188 2016-03-09 19:00:00 2016-03-01 #> 189 2016-03-09 20:00:00 2016-03-01 #> 190 2016-03-09 21:00:00 2016-03-01 #> 191 2016-03-09 22:00:00 2016-03-01 #> 192 2016-03-09 23:00:00 2016-03-01 #> 193 2016-03-10 00:00:00 2016-03-01 #> 194 2016-03-10 01:00:00 2016-03-01 #> 195 2016-03-10 02:00:00 2016-03-01 #> 196 2016-03-10 03:00:00 2016-03-01 #> 197 2016-03-10 04:00:00 2016-03-01 #> 198 2016-03-10 05:00:00 2016-03-01 #> 199 2016-03-10 06:00:00 2016-03-01 #> 200 2016-03-10 07:00:00 2016-03-01
thicken(some_df, 'day', start_val = lubridate::ymd_hms('20160301 120000'))
#> x_hour x_hour_day #> 1 2016-03-02 00:00:00 2016-03-01 12:00:00 #> 2 2016-03-02 01:00:00 2016-03-01 12:00:00 #> 3 2016-03-02 02:00:00 2016-03-01 12:00:00 #> 4 2016-03-02 03:00:00 2016-03-01 12:00:00 #> 5 2016-03-02 04:00:00 2016-03-01 12:00:00 #> 6 2016-03-02 05:00:00 2016-03-01 12:00:00 #> 7 2016-03-02 06:00:00 2016-03-01 12:00:00 #> 8 2016-03-02 07:00:00 2016-03-01 12:00:00 #> 9 2016-03-02 08:00:00 2016-03-01 12:00:00 #> 10 2016-03-02 09:00:00 2016-03-01 12:00:00 #> 11 2016-03-02 10:00:00 2016-03-01 12:00:00 #> 12 2016-03-02 11:00:00 2016-03-01 12:00:00 #> 13 2016-03-02 12:00:00 2016-03-02 12:00:00 #> 14 2016-03-02 13:00:00 2016-03-02 12:00:00 #> 15 2016-03-02 14:00:00 2016-03-02 12:00:00 #> 16 2016-03-02 15:00:00 2016-03-02 12:00:00 #> 17 2016-03-02 16:00:00 2016-03-02 12:00:00 #> 18 2016-03-02 17:00:00 2016-03-02 12:00:00 #> 19 2016-03-02 18:00:00 2016-03-02 12:00:00 #> 20 2016-03-02 19:00:00 2016-03-02 12:00:00 #> 21 2016-03-02 20:00:00 2016-03-02 12:00:00 #> 22 2016-03-02 21:00:00 2016-03-02 12:00:00 #> 23 2016-03-02 22:00:00 2016-03-02 12:00:00 #> 24 2016-03-02 23:00:00 2016-03-02 12:00:00 #> 25 2016-03-03 00:00:00 2016-03-02 12:00:00 #> 26 2016-03-03 01:00:00 2016-03-02 12:00:00 #> 27 2016-03-03 02:00:00 2016-03-02 12:00:00 #> 28 2016-03-03 03:00:00 2016-03-02 12:00:00 #> 29 2016-03-03 04:00:00 2016-03-02 12:00:00 #> 30 2016-03-03 05:00:00 2016-03-02 12:00:00 #> 31 2016-03-03 06:00:00 2016-03-02 12:00:00 #> 32 2016-03-03 07:00:00 2016-03-02 12:00:00 #> 33 2016-03-03 08:00:00 2016-03-02 12:00:00 #> 34 2016-03-03 09:00:00 2016-03-02 12:00:00 #> 35 2016-03-03 10:00:00 2016-03-02 12:00:00 #> 36 2016-03-03 11:00:00 2016-03-02 12:00:00 #> 37 2016-03-03 12:00:00 2016-03-03 12:00:00 #> 38 2016-03-03 13:00:00 2016-03-03 12:00:00 #> 39 2016-03-03 14:00:00 2016-03-03 12:00:00 #> 40 2016-03-03 15:00:00 2016-03-03 12:00:00 #> 41 2016-03-03 16:00:00 2016-03-03 12:00:00 #> 42 2016-03-03 17:00:00 2016-03-03 12:00:00 #> 43 2016-03-03 18:00:00 2016-03-03 12:00:00 #> 44 2016-03-03 19:00:00 2016-03-03 12:00:00 #> 45 2016-03-03 20:00:00 2016-03-03 12:00:00 #> 46 2016-03-03 21:00:00 2016-03-03 12:00:00 #> 47 2016-03-03 22:00:00 2016-03-03 12:00:00 #> 48 2016-03-03 23:00:00 2016-03-03 12:00:00 #> 49 2016-03-04 00:00:00 2016-03-03 12:00:00 #> 50 2016-03-04 01:00:00 2016-03-03 12:00:00 #> 51 2016-03-04 02:00:00 2016-03-03 12:00:00 #> 52 2016-03-04 03:00:00 2016-03-03 12:00:00 #> 53 2016-03-04 04:00:00 2016-03-03 12:00:00 #> 54 2016-03-04 05:00:00 2016-03-03 12:00:00 #> 55 2016-03-04 06:00:00 2016-03-03 12:00:00 #> 56 2016-03-04 07:00:00 2016-03-03 12:00:00 #> 57 2016-03-04 08:00:00 2016-03-03 12:00:00 #> 58 2016-03-04 09:00:00 2016-03-03 12:00:00 #> 59 2016-03-04 10:00:00 2016-03-03 12:00:00 #> 60 2016-03-04 11:00:00 2016-03-03 12:00:00 #> 61 2016-03-04 12:00:00 2016-03-04 12:00:00 #> 62 2016-03-04 13:00:00 2016-03-04 12:00:00 #> 63 2016-03-04 14:00:00 2016-03-04 12:00:00 #> 64 2016-03-04 15:00:00 2016-03-04 12:00:00 #> 65 2016-03-04 16:00:00 2016-03-04 12:00:00 #> 66 2016-03-04 17:00:00 2016-03-04 12:00:00 #> 67 2016-03-04 18:00:00 2016-03-04 12:00:00 #> 68 2016-03-04 19:00:00 2016-03-04 12:00:00 #> 69 2016-03-04 20:00:00 2016-03-04 12:00:00 #> 70 2016-03-04 21:00:00 2016-03-04 12:00:00 #> 71 2016-03-04 22:00:00 2016-03-04 12:00:00 #> 72 2016-03-04 23:00:00 2016-03-04 12:00:00 #> 73 2016-03-05 00:00:00 2016-03-04 12:00:00 #> 74 2016-03-05 01:00:00 2016-03-04 12:00:00 #> 75 2016-03-05 02:00:00 2016-03-04 12:00:00 #> 76 2016-03-05 03:00:00 2016-03-04 12:00:00 #> 77 2016-03-05 04:00:00 2016-03-04 12:00:00 #> 78 2016-03-05 05:00:00 2016-03-04 12:00:00 #> 79 2016-03-05 06:00:00 2016-03-04 12:00:00 #> 80 2016-03-05 07:00:00 2016-03-04 12:00:00 #> 81 2016-03-05 08:00:00 2016-03-04 12:00:00 #> 82 2016-03-05 09:00:00 2016-03-04 12:00:00 #> 83 2016-03-05 10:00:00 2016-03-04 12:00:00 #> 84 2016-03-05 11:00:00 2016-03-04 12:00:00 #> 85 2016-03-05 12:00:00 2016-03-05 12:00:00 #> 86 2016-03-05 13:00:00 2016-03-05 12:00:00 #> 87 2016-03-05 14:00:00 2016-03-05 12:00:00 #> 88 2016-03-05 15:00:00 2016-03-05 12:00:00 #> 89 2016-03-05 16:00:00 2016-03-05 12:00:00 #> 90 2016-03-05 17:00:00 2016-03-05 12:00:00 #> 91 2016-03-05 18:00:00 2016-03-05 12:00:00 #> 92 2016-03-05 19:00:00 2016-03-05 12:00:00 #> 93 2016-03-05 20:00:00 2016-03-05 12:00:00 #> 94 2016-03-05 21:00:00 2016-03-05 12:00:00 #> 95 2016-03-05 22:00:00 2016-03-05 12:00:00 #> 96 2016-03-05 23:00:00 2016-03-05 12:00:00 #> 97 2016-03-06 00:00:00 2016-03-05 12:00:00 #> 98 2016-03-06 01:00:00 2016-03-05 12:00:00 #> 99 2016-03-06 02:00:00 2016-03-05 12:00:00 #> 100 2016-03-06 03:00:00 2016-03-05 12:00:00 #> 101 2016-03-06 04:00:00 2016-03-05 12:00:00 #> 102 2016-03-06 05:00:00 2016-03-05 12:00:00 #> 103 2016-03-06 06:00:00 2016-03-05 12:00:00 #> 104 2016-03-06 07:00:00 2016-03-05 12:00:00 #> 105 2016-03-06 08:00:00 2016-03-05 12:00:00 #> 106 2016-03-06 09:00:00 2016-03-05 12:00:00 #> 107 2016-03-06 10:00:00 2016-03-05 12:00:00 #> 108 2016-03-06 11:00:00 2016-03-05 12:00:00 #> 109 2016-03-06 12:00:00 2016-03-06 12:00:00 #> 110 2016-03-06 13:00:00 2016-03-06 12:00:00 #> 111 2016-03-06 14:00:00 2016-03-06 12:00:00 #> 112 2016-03-06 15:00:00 2016-03-06 12:00:00 #> 113 2016-03-06 16:00:00 2016-03-06 12:00:00 #> 114 2016-03-06 17:00:00 2016-03-06 12:00:00 #> 115 2016-03-06 18:00:00 2016-03-06 12:00:00 #> 116 2016-03-06 19:00:00 2016-03-06 12:00:00 #> 117 2016-03-06 20:00:00 2016-03-06 12:00:00 #> 118 2016-03-06 21:00:00 2016-03-06 12:00:00 #> 119 2016-03-06 22:00:00 2016-03-06 12:00:00 #> 120 2016-03-06 23:00:00 2016-03-06 12:00:00 #> 121 2016-03-07 00:00:00 2016-03-06 12:00:00 #> 122 2016-03-07 01:00:00 2016-03-06 12:00:00 #> 123 2016-03-07 02:00:00 2016-03-06 12:00:00 #> 124 2016-03-07 03:00:00 2016-03-06 12:00:00 #> 125 2016-03-07 04:00:00 2016-03-06 12:00:00 #> 126 2016-03-07 05:00:00 2016-03-06 12:00:00 #> 127 2016-03-07 06:00:00 2016-03-06 12:00:00 #> 128 2016-03-07 07:00:00 2016-03-06 12:00:00 #> 129 2016-03-07 08:00:00 2016-03-06 12:00:00 #> 130 2016-03-07 09:00:00 2016-03-06 12:00:00 #> 131 2016-03-07 10:00:00 2016-03-06 12:00:00 #> 132 2016-03-07 11:00:00 2016-03-06 12:00:00 #> 133 2016-03-07 12:00:00 2016-03-07 12:00:00 #> 134 2016-03-07 13:00:00 2016-03-07 12:00:00 #> 135 2016-03-07 14:00:00 2016-03-07 12:00:00 #> 136 2016-03-07 15:00:00 2016-03-07 12:00:00 #> 137 2016-03-07 16:00:00 2016-03-07 12:00:00 #> 138 2016-03-07 17:00:00 2016-03-07 12:00:00 #> 139 2016-03-07 18:00:00 2016-03-07 12:00:00 #> 140 2016-03-07 19:00:00 2016-03-07 12:00:00 #> 141 2016-03-07 20:00:00 2016-03-07 12:00:00 #> 142 2016-03-07 21:00:00 2016-03-07 12:00:00 #> 143 2016-03-07 22:00:00 2016-03-07 12:00:00 #> 144 2016-03-07 23:00:00 2016-03-07 12:00:00 #> 145 2016-03-08 00:00:00 2016-03-07 12:00:00 #> 146 2016-03-08 01:00:00 2016-03-07 12:00:00 #> 147 2016-03-08 02:00:00 2016-03-07 12:00:00 #> 148 2016-03-08 03:00:00 2016-03-07 12:00:00 #> 149 2016-03-08 04:00:00 2016-03-07 12:00:00 #> 150 2016-03-08 05:00:00 2016-03-07 12:00:00 #> 151 2016-03-08 06:00:00 2016-03-07 12:00:00 #> 152 2016-03-08 07:00:00 2016-03-07 12:00:00 #> 153 2016-03-08 08:00:00 2016-03-07 12:00:00 #> 154 2016-03-08 09:00:00 2016-03-07 12:00:00 #> 155 2016-03-08 10:00:00 2016-03-07 12:00:00 #> 156 2016-03-08 11:00:00 2016-03-07 12:00:00 #> 157 2016-03-08 12:00:00 2016-03-08 12:00:00 #> 158 2016-03-08 13:00:00 2016-03-08 12:00:00 #> 159 2016-03-08 14:00:00 2016-03-08 12:00:00 #> 160 2016-03-08 15:00:00 2016-03-08 12:00:00 #> 161 2016-03-08 16:00:00 2016-03-08 12:00:00 #> 162 2016-03-08 17:00:00 2016-03-08 12:00:00 #> 163 2016-03-08 18:00:00 2016-03-08 12:00:00 #> 164 2016-03-08 19:00:00 2016-03-08 12:00:00 #> 165 2016-03-08 20:00:00 2016-03-08 12:00:00 #> 166 2016-03-08 21:00:00 2016-03-08 12:00:00 #> 167 2016-03-08 22:00:00 2016-03-08 12:00:00 #> 168 2016-03-08 23:00:00 2016-03-08 12:00:00 #> 169 2016-03-09 00:00:00 2016-03-08 12:00:00 #> 170 2016-03-09 01:00:00 2016-03-08 12:00:00 #> 171 2016-03-09 02:00:00 2016-03-08 12:00:00 #> 172 2016-03-09 03:00:00 2016-03-08 12:00:00 #> 173 2016-03-09 04:00:00 2016-03-08 12:00:00 #> 174 2016-03-09 05:00:00 2016-03-08 12:00:00 #> 175 2016-03-09 06:00:00 2016-03-08 12:00:00 #> 176 2016-03-09 07:00:00 2016-03-08 12:00:00 #> 177 2016-03-09 08:00:00 2016-03-08 12:00:00 #> 178 2016-03-09 09:00:00 2016-03-08 12:00:00 #> 179 2016-03-09 10:00:00 2016-03-08 12:00:00 #> 180 2016-03-09 11:00:00 2016-03-08 12:00:00 #> 181 2016-03-09 12:00:00 2016-03-09 12:00:00 #> 182 2016-03-09 13:00:00 2016-03-09 12:00:00 #> 183 2016-03-09 14:00:00 2016-03-09 12:00:00 #> 184 2016-03-09 15:00:00 2016-03-09 12:00:00 #> 185 2016-03-09 16:00:00 2016-03-09 12:00:00 #> 186 2016-03-09 17:00:00 2016-03-09 12:00:00 #> 187 2016-03-09 18:00:00 2016-03-09 12:00:00 #> 188 2016-03-09 19:00:00 2016-03-09 12:00:00 #> 189 2016-03-09 20:00:00 2016-03-09 12:00:00 #> 190 2016-03-09 21:00:00 2016-03-09 12:00:00 #> 191 2016-03-09 22:00:00 2016-03-09 12:00:00 #> 192 2016-03-09 23:00:00 2016-03-09 12:00:00 #> 193 2016-03-10 00:00:00 2016-03-09 12:00:00 #> 194 2016-03-10 01:00:00 2016-03-09 12:00:00 #> 195 2016-03-10 02:00:00 2016-03-09 12:00:00 #> 196 2016-03-10 03:00:00 2016-03-09 12:00:00 #> 197 2016-03-10 04:00:00 2016-03-09 12:00:00 #> 198 2016-03-10 05:00:00 2016-03-09 12:00:00 #> 199 2016-03-10 06:00:00 2016-03-09 12:00:00 #> 200 2016-03-10 07:00:00 2016-03-09 12:00:00
library(dplyr) x_df <- data.frame( x = seq(lubridate::ymd(20130101), by = 'day', length.out = 1000) %>% sample(500), y = runif(500, 10, 50) %>% round) %>% arrange(x) # get the max per month x_df %>% thicken('month') %>% group_by(x_month) %>% summarise(y_max = max(y))
#> # A tibble: 33 x 2 #> x_month y_max #> <date> <dbl> #> 1 2013-01-01 36 #> 2 2013-02-01 50 #> 3 2013-03-01 49 #> 4 2013-04-01 48 #> 5 2013-05-01 48 #> 6 2013-06-01 48 #> 7 2013-07-01 50 #> 8 2013-08-01 44 #> 9 2013-09-01 47 #> 10 2013-10-01 44 #> # … with 23 more rows
# get the average per week, but you want your week to start on Mondays # instead of Sundays x_df %>% thicken('week', start_val = closest_weekday(x_df$x, 2)) %>% group_by(x_week) %>% summarise(y_avg = mean(y))
#> # A tibble: 142 x 2 #> x_week y_avg #> <date> <dbl> #> 1 2013-01-08 20 #> 2 2013-01-15 18.8 #> 3 2013-01-22 11 #> 4 2013-01-29 35.2 #> 5 2013-02-05 36.8 #> 6 2013-02-12 30.7 #> 7 2013-02-19 33.5 #> 8 2013-02-26 28 #> 9 2013-03-05 45 #> 10 2013-03-12 37.5 #> # … with 132 more rows
# rounding up instead of down x <- data.frame(dt = lubridate::ymd_hms('20171021 160000', '20171021 163100')) thicken(x, interval = "hour", rounding = "up")
#> dt dt_hour #> 1 2017-10-21 16:00:00 2017-10-21 17:00:00 #> 2 2017-10-21 16:31:00 2017-10-21 17:00:00
thicken(x, interval = "hour", rounding = "up", ties_to_earlier = TRUE)
#> dt dt_hour #> 1 2017-10-21 16:00:00 2017-10-21 16:00:00 #> 2 2017-10-21 16:31:00 2017-10-21 17:00:00