Skip to content

Expand auto indexing to >, >=, <, <= and != #1068

Open

Description

@arunsrinivasan
  • >
  • >=
  • <
  • <=
  • !=
  • %chin%
  • x[is.na(.)]
  • x[which.max(.)]
  • !=
  • %inrange%

Activity

  1. juanpide commented on Apr 25, 2015

    @juanpide

    Could you give more details, please?

  2. DavidArenburg commented on Jul 14, 2015

    @DavidArenburg
    Member

    +10 for that

  3. added this to the v1.9.8 milestone on Nov 30, 2015
  4. changed the title [-]Expand auto indexing to >, >=, < and <=[/-] [+]Expand auto indexing to >, >=, <, <= and !=[/+] on Nov 30, 2015
  5. modified the milestones: , v1.9.8 on Mar 20, 2016
  6. arunsrinivasan commented on Mar 20, 2016

    @arunsrinivasan
    MemberAuthor

    Will have to do that after rolling out non-equi joins.. moving to 2.0

  7. franknarf1 commented on Mar 14, 2017

    @franknarf1
    Contributor

    Also, %between% (though is that just a special case of inrange, which is already listed above?).

    For example, this SO question could be done efficiently with it, I guess. Suppose the goal is to set x to 0 outside the closed interval [-90, 90]:

    library(data.table)
    data <- data.table(x = c(10, -10, 20, -20, 100, -100))
    
    # this should be fairly fast if between uses auto indexing
    data[, tmp_x := numeric(.N) ][between(x, -90, 90), tmp_x := x ][, x := NULL]
    setnames(data, "tmp_x", "x")
    

    Or even simpler if logical operations are also supported (#1453):

    data[!between(x, -90, 90), x := 0 ]
    

    Another: https://stackoverflow.com/a/48995696/

  8. juanpide commented on Mar 14, 2017

    @juanpide

    @franknarf1 maybe you mean as.numeric instead of numeric ?

  9. franknarf1 commented on Mar 14, 2017

    @franknarf1
    Contributor

    @skanskan No, I'm initializing to zero with numeric then overwriting in the subset between -90 and 90.

  10. juanpide commented on Mar 14, 2017

    @juanpide

    @franknarf1 Why not just tmp_x := 0 ?

  11. franknarf1 commented on Mar 14, 2017

    @franknarf1
    Contributor

    @skanskan No reason. Sorry for the confusion.

    Editing in SO links...

    Count other people with a higher score in the last 30 days -- seems a good fit for != df[, v := 1L + df[.(s = Score, n = Name, d_dn = Date - 30, d_up = Date), on=.(Name != n, Score > s, Date >= d_dn, Date <= d_up), .N, by=.EACHI]]

  12. removed this from the milestone on May 10, 2018
  13. gregorp commented on Feb 22, 2022

    @gregorp

    Would this allow for using != as an operator in non-equi joins?

  14. MichaelChirico commented on Feb 24, 2022

    @MichaelChirico
    Member

    I think that conversely != as an operator is a pre-cursor for this issue

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions