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

Strange row_number results #227

Closed
juba opened this issue Jan 30, 2014 · 1 comment
Closed

Strange row_number results #227

juba opened this issue Jan 30, 2014 · 1 comment

Comments

@juba
Copy link

@juba juba commented Jan 30, 2014

Take the following data frame :

tmp <- data.frame(id=rep(c(1,2),each=5),value=c(1,1,2,5,0,6,4,0,0,2))

I'd like to apply row_number group-wise with the following :

group_by(tmp, "id") %.% mutate(var=row_number(value))

But the result is clearly wrong :

   id value var
1   1     1   5
2   1     1   1
3   1     2   2
4   1     5   3
5   1     0   4
6   2     6   3
7   2     4   4
8   2     0   5
9   2     0   2
10  2     2   1

What is strange is that if I just remove the last 2 lines of my data frame, the result is correct :

tmp <- data.frame(id=rep(c(1,2),each=4),value=c(1,1,2,5,0,6,4,0))
group_by(tmp, "id") %.% mutate(var=row_number(value))

Maybe I'm doing something wrong, but this seems rather strange to me.

Thanks !

@romainfrancois
Copy link
Member

@romainfrancois romainfrancois commented Jan 30, 2014

Thanks. There were in fact two problems. Should be fixed now.

Loading

@lock lock bot locked as resolved and limited conversation to collaborators Jun 11, 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
2 participants