Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lead() on grouped data is buggy #937

alex23lemm opened this issue Jan 30, 2015 · 2 comments

lead() on grouped data is buggy #937

alex23lemm opened this issue Jan 30, 2015 · 2 comments


Copy link

@alex23lemm alex23lemm commented Jan 30, 2015

This is a follow up on #925 which fixed lag() on grouped data.

The same issue exists also for lead() when data is grouped and wasn't fixed yet in the current dev version:

df <- data.frame(name=rep(c('Al','Jen'),3),
                score=rep(c(100, 80, 60),2))
 df %>%
   group_by(name) %>%
   mutate(next.score = lead(score),
          before.score = lag(score) )
#   name score next.score before.score
#1   Al   100         80           NA
#2  Jen    80         60           NA
#3   Al    60        100          100
#4  Jen   100         80           80
#5   Al    80         NA           60
#6  Jen    60         NA          100

For instance, next.score for Al in line 1 should be 60 and not 80.

Following the fix of #925 I assume that Lead.h in line 52 needs to be modified from out[out_index[i]] = data[index[i]+n] ; to out[out_index[i]] = data[index[i+n]] ;

Copy link

@romainfrancois romainfrancois commented Feb 5, 2015

Thanks. That was indeed the right fix. Given that you found it, perhaps you could have submitted a pull request ?


@romainfrancois romainfrancois self-assigned this Feb 5, 2015
Copy link

@alex23lemm alex23lemm commented Feb 5, 2015

Thanks for the feedback and the fix! You're right, I should have submitted a pull request. I doubt that there will be a second chance given the excellent state of the package :-).



@lock lock bot locked as resolved and limited conversation to collaborators Jun 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants