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
rowwise() giving incorrect result in some situations #1448
Comments
A similar, probably related bug : https://stackoverflow.com/questions/33107956/dplyrmutate-gives-x-y-na-summarise-gives-x-y-real-number Pass <- data.frame(P2 = c(0,3,2), F2 = c(0,2,0), id = 1:3)
#these two both fail
Pass %>% group_by(id) %>% mutate(pass2 = P2/(P2 + F2))
Pass %>% rowwise %>% mutate(pass2 = P2/(P2 + F2)) Both give an NA in the last row of pass2: Source: local data frame [3 x 4]
Groups: <by row>
P2 F2 id pass2
(dbl) (dbl) (int) (dbl)
1 0 0 1 NA
2 3 2 2 0.6
3 2 0 3 NA Whereas without rowwise or grouping, it works as expected: Pass %>% mutate(pass2 = P2/(P2 + F2))
P2 F2 id pass2
1 0 0 1 NaN
2 3 2 2 0.6
3 2 0 3 1.0 |
I had the same issue in an unbalanced dataset, where I needed grouping! And it was also only the third group_id that had NA's (as many as rows this id had)! Using
See my answer in the discussion on stackoverflow above. But it seems strange that it is always the third group, where NA's appear:
Look's like a little bug... |
I suspect these are three separate bugs. |
The first problem has been otherwise taken care of, but I've added a regression test anyway. We are now consistently getting:
|
For the second problem, we get
I think I know what this is about. |
Yep. This was because Rcpp's
ping @kevinushey |
Hi guys. Granted that this is not generally a row-wise operation, I still think it would be good to bring to your attention. The issue came about on Stack Overflow, where an error was discovered in the resulting data frame.
http://stackoverflow.com/questions/33090745/dplyrrowwise-mutate-and-na-error
A minimal example is as follows
We believe that row 3, column
l
should be 1, not NA as shown.If you run the following code a few separate times, you will find that the incident above only occurs intermittently.
The text was updated successfully, but these errors were encountered: