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

[R-Forge #203] Allow 2 column to specify range in i instead of %between% #679

Closed
arunsrinivasan opened this issue Jun 8, 2014 · 2 comments
Assignees
Milestone

Comments

@arunsrinivasan
Copy link
Member

Submitted by: Matt Dowle; Assigned to: Nobody; R-Forge link

%between% is currently a vector scan.
Instead allow DT[J(id,DT(from,to)),...]
where the i is a data.list, from and to are equi-joined, and the range between them returned. Depends on non vectors being allowed in a data.table.

@arunsrinivasan
Copy link
Member Author

From Lucas' email - here for reference as this is closely related. Refer to the email exchange with Xavier/Lucas for more info:

require(data.table)

set.seed(45L)
DT_USER <- unique(data.table(UID=1:10, UTIME=sample(10, 30, TRUE)))
DT_USER <- DT_USER[order(UID, UTIME)]

DT_TRANSACTION <- data.table(TIME=1:10, AMOUNT=sample(100, 10, TRUE))

# This is what i really want, join user and transaction,
# but faster than doing the full cartesian product and cosuming less memory too
DT_USER[, DUMMY := 1]
DT_TRANSACTION[, DUMMY := 1]

DT_RESULT <- merge(DT_USER, DT_TRANSACTION, by="DUMMY",
                   allow.cartesian=TRUE)
DT_RESULT[, DUMMY := NULL]
DT_RESULT <- DT_RESULT[TIME <= UTIME]

This requires a full join followed by a subset, which of course can and should be avoided! Thanks a lot Lucas.

@arunsrinivasan arunsrinivasan added this to the v1.9.6 milestone Sep 24, 2014
@arunsrinivasan arunsrinivasan modified the milestones: v1.9.6, v1.9.8 Oct 10, 2014
@arunsrinivasan
Copy link
Member Author

Lucas' Q can now be done with:

DT_TRANSACTION[DT_USER, on="TIME<=UTIME", allow.cartesian=TRUE]
# or
DT_TRANSACTION[DT_USER, on=.(TIME<=UTIME), allow.cartesian=TRUE]

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

No branches or pull requests

1 participant