Assuming I have a dict
d:flip(100 200 400 800 1600; 1 3 4 6 10)
how can I create a lookup function that returns the value of the smallest key that is larger than x? Given a table
tbl:flip `sym`val!(`a`b`c`d; 50 280 1200 1800)
I would like to do something like
{[x] : update new:fun[x[`val]] from x} each tbl
to end up at a table like this
tbl:flip `sym`val`new!(`a`b`c`d; 50 280 1200 1800; 1 4 10 0N)
sym val new
a 50 1
b 280 4
c 1200 10
d 1800
I think you will want to use
binr
to return the next element greater than or equal tox
. Note that you should use a sorted list for this to work correctly. For the examples above, convertingd
to a dictionary withd:(!). flip d
I came up with:Where you get the dictionary keys to use with:
k k binr tbl`val
.Edit: if the value in the table needs to be mapped to a value greater than
x
but not equal to, you could try: