Next: Knit Functions, Previous: Expression, Up: Top
This chapter covers the built-in named functions. This includes some math (eg. sqrt but not +), wrapper (eg. count for #) and range (eg. within) functions.
rand has bin in within div mod bar rand cmb msum mavg count first last sum min max *[avg var dev med ..]; key meta
exp compute the exponent of x, i.e. ex.
exp 1 2.718282
Log computes the natural log.
log 10 2.302585
sin computes the sine of x where x is in radians.
sin 0 0f sin 3.1416%2 1.
cos computes the cosine of x where x is in radians.
cos 0 1f cos 3.1416%4 0.7071055
Compute the square of x.
sqr 2 4.0
Compute the square root of x.
sqrt 2 1.414214
Write out all permutations of integers up x-1. Display them as columns.
prm 3 0 1 1 0 2 2 1 0 2 2 0 1 2 2 0 1 1 0
Compute the frequency of the items in list x.
freq "abzccdefeajfekjrlke" a|2 b|1 c|2 d|1 e|4 f|2 j|2 k|2 l|1 r|1 z|1 freq 1000 rand 10 0| 95 1|106 2| 84 3| 98 4|109 5|104 6| 94 7| 95 8|120 9| 95
Compute the running sum of list x. Sames as +\
.
sums !10 0 1 3 6 10 15 21 28 36 45
Compute the difference between each element in list x and the previous value. If delta is called with two parameters then x will be used as the first value to delta instead of the default 0.
deltas 1 5 10 1 4 5 1 deltas 1 5 10 0 4 5
Generate x random values using a uniform distribution from [0,1) or -x random values of a normal distribution (mean=0, standard deviation=1).
rand 5 / uniform 0.9722755 0.8904738 0.4088624 0.1399796 0.1334422 rand -5 / normal 1.008461 0.6204548 -1.206095 -0.7168573 -0.5728272
Generate x random values from element or list y. For element y, y is the exclusive upper bound (int, float, date, or time), the type (character), or the length of each element (name). For list y, rand choose between elements of the list.
5 rand 10 / values between 0 and 9 3 0 0 7 8 4 rand "a" / values between "A" and "P" "OGFN" 4 rand `3 / name of length 3 using letters between "A" and "P" `BFH`HKH`LOO`DAC 5 rand 1 2 1 2 2 1 1 5 rand "xy" "yxxxy"
Determine whether vector x has element y. Simliar to in but with the arguments reversed.
`a`b`c`a`b has `a 1b `a`b`c`a`b has `d 0b `a`b`c`a`b has `a`b`x`y`z 11000b (1 2;4 5 6;7 9)has(1 2;8 9) 10b
Given a sorted (increasing) list x, find the greatest index, i, where y>x[i].
n:exp 0.01*!5;n 1 1.01005 1.020201 1.030455 1.040811 1.025 bin n 2
Determine if x is in list y. Similar to has but arguments reversed.
`b in `a`b`d`e 1b `c in `a`b`d`e 0b
Test if x is equal to or greater than y[0] and less than y[1].
3 within 0 12 1b 0 within 0 12 1b 12 within 0 12 0b 23 within 0 12 0b
y divided by x using integer division, taking the floor of the result. x and y must be integers.
2 div 7 3 5 div 22 4
The remainder after y divided by x using integer division. x and y must be integers.
12 mod 27 3 5 mod 22 2
For each value in y determine the maximum multiple of x that is less than or equal to each y.
10 bar 9 10 11 19 20 21 0 10 10 10 20 20
Determine all x value combinations up to y. In this case these are ordered in ascending order from left to right.
3 cmb 5 2 3 4 1 3 4 1 2 4 1 2 3 0 3 4 0 2 4 0 2 3 0 1 4 0 1 3 0 1 2 `a`b`c`d`e@3 cmb 5 `c`d`e `b`d`e `b`c`e `b`c`d `a`d`e `a`c`e `a`c`d `a`b`e `a`b`d `a`b`c
Compute the length x moving sum of list y.
3 msum !10 0 1 3 6 9 12 15 18 21 24
Compute the length x moving average of list y.
3 mavg !10 0 0.3333333 1 2 3 4 5 6 7 8
Same as count.
count 5 1 2 3
Same as first.
first 5 1 2 5
Retrieve the last element of list x.
last 5 1 2 2
Compute the sum of list x. Same as +/
.
sum 5 1 2 8
Retrieve the minimum element of list x. Same as |/
.
min 5 1 2 1
Retrieve the maximum element of list x. Same as &/
.
max 5 1 2 5
Return the index of the max value of list x.
top 3 13 15 1 17 0 -3 4 top "abzccdefeajfekjrlke" 2
Key table y with x. That is, the values in the x column become the key values.
`a key [[]a:`fa`fb;b:1 2] a |b --|- fa|1 fb|2 `a key [[]a:`fa`fb;b:((1 2 3); (4 5 6))] a |b --|----- fa|1 2 3 fb|4 5 6
Remove key from table x.
unkey [[a:`x`y]b:1 2] a b - - x 1 y 2
Determine the types of the fields in a table.
meta [[]a:`x`y;b:1 2] a|n b|i
Next: Knit Functions, Previous: Expression, Up: Top