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

split.data.table does not respect factor ordering #2082

Closed
MichaelChirico opened this issue Mar 27, 2017 · 3 comments
Closed

split.data.table does not respect factor ordering #2082

MichaelChirico opened this issue Mar 27, 2017 · 3 comments
Milestone

Comments

@MichaelChirico
Copy link
Member

@MichaelChirico MichaelChirico commented Mar 27, 2017

Pretty self-explanatory. MWE:

DT = data.table(a = factor(c('a', 'b'), levels = c('b', 'a')))
split(DT, by = 'a', sorted = TRUE)
# $a
#    a
# 1: a

# $b
#    a
# 1: b
split(DT, f = DT$a, sorted = TRUE)
# $b
#    a
# 1: b

# $a
#    a
# 1: a
split.data.frame(DT, f = DT$a)
# $b
#    a
# 1: b

# $a
#    a
# 1: a
@jangorecki
Copy link
Member

@jangorecki jangorecki commented Mar 29, 2017

AFAIR when using f argument then sorted is ignored. I don't see the point in extending f use case features when it is recommended to use by. f is less efficient, it is there so data.frame code can work with data.table method. Using by here is solution good enough, correct?

@MichaelChirico
Copy link
Member Author

@MichaelChirico MichaelChirico commented Mar 29, 2017

@jangorecki I should have added more exposition. the focus is the first example, where I use by but the output order is incorrect. But the order IS correct when I use f not by

@MichaelChirico
Copy link
Member Author

@MichaelChirico MichaelChirico commented Mar 31, 2017

@jangorecki check my PR. You're right that if we use f it's going to be less efficient, since internally it basically just passes to split.data.frame in this case.

However as mentioned, what I was intending to do was indeed use by, but it was giving incorrect output. That should be fixed now.

@mattdowle mattdowle added this to the v1.10.6 milestone Aug 5, 2017
@mattdowle mattdowle closed this in 62eba28 Aug 5, 2017
mattdowle added a commit that referenced this issue Aug 5, 2017
Closes #2082 -- split.data.table respects factor ordering
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants