- KDB+ 教程
- KDB+ - 首頁
- Q 程式語言
- Q 程式語言
- Q 語言 - 型別轉換
- Q 語言 - 時間資料
- Q 語言 - 列表
- Q 語言 - 索引
- Q 語言 - 字典
- Q 語言 - 表格
- Q 語言 - 動詞 & 副詞
- Q 語言 - 連線
- Q 語言 - 函式
- Q 語言 - 內建函式
- Q 語言 - 查詢
- Q - 程序間通訊
- Q - 訊息處理器 (.Z 庫)
- KDB+ 有用資源
- KDB+ - 快速指南
- KDB+ - 有用資源
- KDB+ - 討論
Q 語言 - 內建函式
q 程式語言有一套豐富而強大的內建函式。內建函式可以分為以下幾種型別:
字串函式 - 以字串作為輸入並返回字串。
聚合函式 - 以列表作為輸入並返回一個原子。
一致函式 - 以列表作為輸入並返回相同數量的列表。
數學函式 - 以數值引數作為輸入並返回數值引數。
雜項函式 - 除上述以外的所有函式。
字串函式
like - 模式匹配
q)/like is a dyadic, performs pattern matching, return 1b on success else 0b q)"John" like "J??n" 1b q)"John My Name" like "J*" 1b
ltrim - 刪除前導空格
q)/ ltrim - monadic ltrim takes string argument, removes leading blanks q)ltrim " Rick " "Rick "
rtrim - 刪除尾隨空格
q)/rtrim - takes string argument, returns the result of removing trailing blanks q)rtrim " Rick " " Rick"
ss - 字串搜尋
q)/ss - string search, perform pattern matching, same as "like" but return the indices of the matches of the pattern in source. q)"Life is beautiful" ss "i" 1 5 13
trim - 刪除前導和尾隨空格
q)/trim - takes string argument, returns the result of removing leading & trailing blanks q)trim " John " "John"
數學函式
acos - cos 的反函式
q)/acos - inverse of cos, for input between -1 and 1, return float between 0 and pi q)acos 1 0f q)acos -1 3.141593 q)acos 0 1.570796
cor - 給出相關性
q)/cor - the dyadic takes two numeric lists of same count, returns a correlation between the items of the two arguments q)27 18 18 9 0 cor 27 36 45 54 63 -0.9707253
cross - 笛卡爾積
q)/cross - takes atoms or lists as arguments and returns their Cartesian product q)9 18 cross `x`y`z 9 `x 9 `y 9 `z 18 `x 18 `y 18 `z
var - 方差
q)/var - monadic, takes a scaler or numeric list and returns a float equal to the mathematical variance of the items q)var 45 0f q)var 9 18 27 36 101.25
wavg (加權平均數)
q)/wavg - dyadic, takes two numeric lists of the same count and returns the average of the second argument weighted by the first argument. q)1 2 3 4 wavg 200 300 400 500 400f
聚合函式
all - & 操作
q)/all - monadic, takes a scaler or list of numeric type and returns the result of & applied across the items. q)all 0b 0b q)all 9 18 27 36 1b q)all 10 20 30 1b
any - | 操作
q)/any - monadic, takes scaler or list of numeric type and the return the result of | applied across the items q)any 20 30 40 50 1b q)any 20012.02.12 2013.03.11 '20012.02.12
prd - 算術乘積
q)/prd - monadic, takes scaler, list, dictionary or table of numeric type and returns the arithmetic product. q)prd `x`y`z! 10 20 30 6000 q)prd ((1 2; 3 4);(10 20; 30 40)) 10 40 90 160
sum - 算術和
q)/sum - monadic, takes a scaler, list,dictionary or table of numeric type and returns the arithmetic sum. q)sum 2 3 4 5 6 20 q)sum (1 2; 4 5) 5 7
一致函式
deltas - 與其前一項的差值。
q)/deltas -takes a scalar, list, dictionary or table and returns the difference of each item from its predecessor. q)deltas 2 3 5 7 9 2 1 2 2 2 q)deltas `x`y`z!9 18 27 x | 9 y | 9 z | 9
fills - 填充空值
q)/fills - takes scalar, list, dictionary or table of numeric type and returns a c copy of the source in which non-null items are propagated forward to fill nulls q)fills 1 0N 2 0N 4 1 1 2 2 4 q)fills `a`b`c`d! 10 0N 30 0N a | 10 b | 10 c | 30 d | 30
maxs - 累積最大值
q)/maxs - takes scalar, list, dictionary or table and returns the cumulative maximum of the source items. q)maxs 1 2 4 3 9 13 2 1 2 4 4 9 13 13 q)maxs `a`b`c`d!9 18 0 36 a | 9 b | 18 c | 18 d | 36
雜項函式
count - 返回元素個數
q)/count - returns the number of entities in its argument. q)count 10 30 30 3 q)count (til 9) 9 q)count ([]a:9 18 27;b:1.1 2.2 3.3) 3
distinct - 返回不同的實體
q)/distinct - monadic, returns the distinct entities in its argument q)distinct 1 2 3 4 2 3 4 5 6 9 1 2 3 4 5 6 9
except - 第二個引數中不存在的元素。
q)/except - takes a simple list (target) as its first argument and returns a list containing the items of target that are not in its second argument q)1 2 3 4 3 1 except 1 2 3 4 3
fill - 用第一個引數填充空值
q)/fill (^) - takes an atom as its first argument and a list(target) as its second argument and return a list obtained by substituting the first argument for every occurrence of null in target q)42^ 9 18 0N 27 0N 36 9 18 42 27 42 36 q)";"^"Life is Beautiful" "Life;is;Beautiful"
廣告