Skip to content
Discussion options

You must be logged in to vote

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 n column:

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 …

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by phahn57
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants