-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You basically need a single row per arrival; so, yes, you need to encode each row multiple times. Simple example. Some sample data: library(dplyr)
df <- data.frame(
time = hms::as_hms(seq(7*60*60, 8*60*60, by=15*60)),
n = rpois(5, 2)
)
df
#> time n
#> 1 07:00:00 1
#> 2 07:15:00 3
#> 3 07:30:00 2
#> 4 07:45:00 1
#> 5 08:00:00 4 The basic way would be to just pick each row that number of times, then you no longer need the df |>
slice(rep(1:n(), n)) |>
select(-n)
#> time
#> 1 07:00:00
#> 2 07:15:00
#> 3 07:15:00
#> 4 07:15:00
#> 5 07:30:00
#> 6 07:30:00
#> 7 07:45:00
#> 8 08:00:00
#> 9 08:00:00
#> 10 08:00:00
#> 11 08:00:00 However, if I understand correctly, you observed those many arrivals for the previous 15 min, which doesn't mean they arrived together at that exact time. So what I would do is to simulate this df |>
rowwise() |>
mutate(t = list(sort(runif(n, 0, 15*60)))) |>
tidyr::unnest_longer(t) |>
mutate(time = hms::as_hms(time - 15*60 + t)) |>
select(-n, -t)
#> # A tibble: 11 × 1
#> time
#> <time>
#> 1 06:59:09.127463
#> 2 07:01:56.243079
#> 3 07:07:01.216664
#> 4 07:12:30.103934
#> 5 07:23:14.985368
#> 6 07:23:17.406660
#> 7 07:33:35.005284
#> 8 07:47:42.738091
#> 9 07:51:04.753963
#> 10 07:56:24.461982
#> 11 07:57:48.193608 which solves a lot of problems that you may encounter when dealing with simultaneous events. |
Beta Was this translation helpful? Give feedback.
-
Thanks I will try both solutions. |
Beta Was this translation helpful? Give feedback.
You basically need a single row per arrival; so, yes, you need to encode each row multiple times.
Simple example. Some sample data:
The basic way would be to just pick each row that number of times, then you no longer need the
n
column:However, if I understand …