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

Weird behavior of group_by + lag #925

Closed
tongcx opened this issue Jan 27, 2015 · 3 comments
Closed

Weird behavior of group_by + lag #925

tongcx opened this issue Jan 27, 2015 · 3 comments
Assignees

Comments

@tongcx
Copy link

@tongcx tongcx commented Jan 27, 2015

library(dplyr)
df = read.csv(text ='
   name time
1   Rob    3
2  Pete    2
3   Rob    5
4  John    3
5   Rob    2
6  Pete    3
7  John    2
8  Pete    4
9  John    1
10 Pete    1
11  Rob    4
12  Rob    1
', sep='')
df %>% group_by(name) %>% mutate(lag_time = lag(time))

Gets me

   name time lag_time
1   Rob    3       NA
2  Pete    2       NA
3   Rob    5        2
4  John    3       NA
5   Rob    2        3
6  Pete    3        2
7  John    2        3
8  Pete    4        2
9  John    1        4
10 Pete    1        1
11  Rob    4        1
12  Rob    1        4

Should row 3 be Rob 5 3? Is this a bug or intended behavior?

@pkanavos
Copy link

@pkanavos pkanavos commented Jan 30, 2015

I can reproduce the problem. It wasn't there with 0.3.2, appeared after upgrading to 0.4.1

Loading

@alex23lemm
Copy link

@alex23lemm alex23lemm commented Jan 30, 2015

I can reproduce the issue as well. With the upgrade to version 0.4.1 the parts of my code using lag on grouped data started producing wrong results.

Here is another SO question showing the current issue.

Loading

@hadley
Copy link
Member

@hadley hadley commented Jan 30, 2015

@romainfrancois can you take a look please?

Loading

@romainfrancois romainfrancois self-assigned this Jan 30, 2015
@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.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants