Skip to content

[R-Forge #5378] mult="first"|"last" changes the output type of [.data.table #340

Closed

Description

@arunsrinivasan

Submitted by: Michele Carriero; Assigned to: Nobody; R-Forge link

Hi there!

Having a data.table dt like:

dt <- data.table(id=rep(1:2,each=2), var=rnorm(4), key="id")

I would expect the following two expression to give the same type of output

dt[.(1:2), list(var)]
#    id         var
#1:  1  0.77227701
#2:  1  1.62441284
#3:  2 -0.04178387
#4:  2  1.20609667

dt[.(1:2), list(var), mult="last"]
#         var
#1: 1.624413
#2: 1.206097

I think having the key column(s) in both expressions is more consistent. The difference is even more noticeable when not using list inside j.

dt[.(1:4), var]
# same than dt[.(1:4), list(var)] because by-without-by
dt[.(1:2), var, mult="last"]
# [1] 1.624413 1.206097

Regardless of by-without-by methodology is not be used, I think each of the queries above should return the same "type" of output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions