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

slice(df,n) for n > nrow(df) inconsistency when using data.tables #1446

Closed
franknarf1 opened this issue Oct 9, 2015 · 0 comments
Closed
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@franknarf1
Copy link

In this SO post, I noticed this difference:

df<-data.frame(Initials=c("a","a","b"),data=c(2,3,4))
my_rows = 1:2

df %>% group_by(Initials) %>% slice(my_rows)
#   Initials  data
#     (fctr) (dbl)
#1        a     2
#2        a     3
#3        b     4

library(data.table)
setDT(df) %>% group_by(Initials) %>% slice(my_rows)
#   Initials  data
#     (fctr) (dbl)
#1        a     2
#2        a     3
#3        b     4
#4        b    NA

Personally, I'd prefer to see the latter behavior and think it's more in keeping with standard R behavior, e.g., in (3:1)[c(5,6)]. However, based on #1269 , I think it clashes with your design goals.

In any case, the two cases should give the same result if dplyr is to play nice with data.table objects.

@hadley hadley added bug an unexpected problem or unintended behavior data table labels Oct 21, 2015
@hadley hadley added this to the 0.5 milestone Oct 21, 2015
@hadley hadley closed this as completed Mar 8, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jun 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants