

mauricelim
Forum Replies Created
-
What you need is actually the (?) vector conditional operator: https://code.kx.com/q/ref/vector-conditional/
? accepts a boolean list as the first argument but $ accepts a boolean atom. Think of ? as a boolean mask.
-
You can use the drop (_) operator, where n is a number to drop.
n_list
To remove from the end of the list:
-n_list neg[n]_list
If you want to remove nulls, you can do something like:
list except 0N
You can use the drop with each (‘) operator to remove the same numbers of items from each list of different length, i.e.
n_'(ls;ls2) -n_'(ls;ls2) neg[n]_'(ls;ls2)
Or removing nulls from them
(ls;ls2)except'0N
-
mauricelim
MemberApril 18, 2022 at 12:00 am in reply to: Generating unique symbol list does not consider symbols after `pThe range of generate for symbols is only from abcdefghijklmnop as documented here: https://code.kx.com/q/ref/deal/#roll-and-deal
As to why is that so, I have no idea as well.
But you can use something like this to solve your problem:
q){[num;len] neg[num]?`${.Q.a cross x}/[len-1;enlist each .Q.a]}[17;1] `e`n`d`g`r`y`b`p`j`l`s`i`f`k`w`u`c q)asc{[num;len] neg[num]?`${.Q.a cross x}/[len-1;enlist each .Q.a]}[256;2] `s#`af`an`aq`as`ax`ay`ba`bd`be`bj`bk`bl`bn`bo`bu`bw`ca`cb`cc`cd`cf`cn`co`cq`c..
-
You could do something like this:
q)fix:{.Q.fmt'[x+1+count each string floor y;x;y]} q)select time,sym,fix[1]price from trade time sym price ------------------------ 09:30:00.000 a "10.8" 09:31:00.000 a "11.8" 09:32:00.000 a "13.2" 09:30:00.000 b "100.8" 09:31:00.000 b "107.0" 09:32:00.000 b "124.0" q)select time,sym,"F"$fix[1]price from trade time sym price ---------------------- 09:30:00.000 a 10.8 09:31:00.000 a 11.8 09:32:00.000 a 13.2 09:30:00.000 b 100.8 09:31:00.000 b 107 09:32:00.000 b 124
Reference: https://code.kx.com/q/ref/dotq/#qfmt-format
Note that if you do cast it back to a float, the decimal does not show for .0
-
mauricelim
MemberNovember 11, 2021 at 12:00 am in reply to: Struggling to understand two statementsYes, it is creating a table schema of specific type for the cols. So when you are manipulating the table, it throws a type error if the type is not of that defined in the schema.
https://code.kx.com/q/ref/insert/#type
More information here: https://code.kx.com/q4m3/8_Tables/#82-empty-tables-and-schema
-
mauricelim
MemberNovember 11, 2021 at 12:00 am in reply to: Struggling to understand two statements1. : represents each left and $ is casting.
https://code.kx.com/q/ref/maps/#each-left-and-each-right
https://code.kx.com/q4m3/7_Transforming_Data/#72-cast
So for the line “nsfi”$:() it is actually casting an empty list with every type on the left (hence each left) so that it creates a list of that specific type. You can use .Q.s1 to view the string representation of the object.
https://code.kx.com/q/ref/dotq/#qs1-string-representation
q)"n"$() `timespan$() q).Q.s1 "nsfi"$:() "(`timespan$();`symbol$();`float$();`int$())"
2. bang (!) is used to create a dictionay with the keys on the left and values on the right with the correct length of list. Then flipping a dict will turn it into a tbl.
https://code.kx.com/q/ref/dict/
https://code.kx.com/q/kb/faq/#flip-a-column-dictionary
3. 2! enkeys the table by the first 2 cols.
https://code.kx.com/q/ref/enkey/
Hope this helps!