Skip to content

Instantly share code, notes, and snippets.

@johnmackintosh
Created May 31, 2018 23:23
Show Gist options
  • Save johnmackintosh/ce6a593db4c6c759b7700af4a1610a5d to your computer and use it in GitHub Desktop.
Save johnmackintosh/ce6a593db4c6c759b7700af4a1610a5d to your computer and use it in GitHub Desktop.
comparing SQL with dplyr
plot_data <- data %>%
mutate(Movement15 = lubridate::floor_date(MovementDateTime,"15 minutes")) %>%
group_by(IN_OUT, Movement_Type,Staging_Post,Movement15) %>%
mutate(counter = case_when(
IN_OUT == 'IN' ~ 1,
IN_OUT == 'OUT' ~ -1)) %>%
mutate(Movement_15_SEQNO = cumsum(counter)) %>%
ungroup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment