I have 1 table in the form as follows:
I want to set c2 to "" when c1>2, expect the result to be like this:
I try to do:
t:([] c1:1 2 3 4;c2:("abcd";"efgh";"igkl";"mnop"))
c:enlist (>; `c1; 2)
b:0b;
a:(enlist `c2)!enlist "";
![t;c;b;a]
But it reported an error: length: Incompatible list lengths Please tell me what to do,thanks.
Since c2
is a list of chars (IE a string) you need to enlist
"" first & then take (#
) the number of strings you need. In this case I've used count[i]
.
q)update c2:count[i]#enlist"" from t where c1>2
c1 c2
---------
1 "abcd"
2 "efgh"
3 ""
4 ""
In functional form:
q)parse"update c2:count[i]#enlist\"\"from t where c1>2"
!
`t
,,(>;`c1;2)
0b
(,`c2)!,(#;(#:;`i);(enlist;""))
q)![t;enlist(>;`c1;2);0b;enlist[`c2]!enlist(#;(count;`i);(enlist;""))]
c1 c2
---------
1 "abcd"
2 "efgh"
3 ""
4 ""