You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
Activity
juanpide commentedon Apr 25, 2015
Could you give more details, please?
DavidArenburg commentedon Jul 14, 2015
+10 for that
[-]Expand auto indexing to >, >=, < and <=[/-][+]Expand auto indexing to >, >=, <, <= and !=[/+]arunsrinivasan commentedon Mar 20, 2016
Will have to do that after rolling out non-equi joins.. moving to 2.0
franknarf1 commentedon Mar 14, 2017
Also,
%between%(though is that just a special case ofinrange, 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]:
Or even simpler if logical operations are also supported (#1453):
Another: https://stackoverflow.com/a/48995696/
juanpide commentedon Mar 14, 2017
@franknarf1 maybe you mean as.numeric instead of numeric ?
franknarf1 commentedon Mar 14, 2017
@skanskan No, I'm initializing to zero with
numericthen overwriting in the subset between -90 and 90.juanpide commentedon Mar 14, 2017
@franknarf1 Why not just tmp_x := 0 ?
franknarf1 commentedon Mar 14, 2017
@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]]gregorp commentedon Feb 22, 2022
Would this allow for using
!=as an operator in non-equi joins?MichaelChirico commentedon Feb 24, 2022
I think that conversely
!=as an operator is a pre-cursor for this issue