Skip to content

Commit

Permalink
Fix disp error with ungrouping (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
steffilazerte committed Jun 27, 2024
1 parent 569664f commit e3f2a14
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions R/transformations.R
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ disp <- function(v, bw = 2, pass = TRUE){
c("animal_id", "logger_id", "date", "start", "end")])

if(nrow(d) > 0) {

d <- d %>%
dplyr::arrange(.data$start) %>%
dplyr::mutate(role = rep(c("displacee", "displacer"), dplyr::n()/2)) %>%
Expand All @@ -859,6 +860,7 @@ disp <- function(v, bw = 2, pass = TRUE){
s <- d %>%
dplyr::group_by(role, animal_id) %>%
dplyr::summarize(n = length(animal_id)) %>%
dplyr::ungroup() %>%
tidyr::complete(animal_id, role, fill = list("n" = 0)) %>%
tidyr::spread(role, n) %>%
dplyr::mutate(p_win = displacer / (displacee + displacer)) %>%
Expand Down

0 comments on commit e3f2a14

Please sign in to comment.