functional modify of all dictionary keys (or column names) in

looking for a function to take an arbitrary k object and modify all dictionary key values (or table columns) with a function

symbol and char vector key types would be most useful, but a general solution is welcome

Hi,

For example:


q) t:flip m:ab`c!(1 2;3 4;5 6)

q) f:10+

q) f each m

a| 11 12
b| 13 14
c| 15 16

q) flip f each flip t

a b c
--------
11 13 15
12 14 16

q) t @[;;f]/cols t
a b c
--------
11 13 15
12 14 16

q) @[;;]/[t;cols t;(10+;20*;30%)]
a b c
-------
11 60 6
12 80 5

q) (10+;20*;30%) @’ m
a| 11 12
b| 60 80
c| 6 5

Regards,

András

Hi, could you please provide an example. 

given some arbitrary k-object:

d:`a`b`c!1 2 3d0:`D`E`F!10 20 30d1:(`$("a_1";"b-2";"c|3"))!100 200 300t:flip`g`h`i!(1 2 3;`a`b`c;1.0 1.1 1.2)a:()!()a[`]:(::)a[`test]:da[`test2]:(1;"a";d0)a[`test3]:(2;"b";`fff;a[`test2];d1)a[`test4]:(a`test3;t;`g xkey t)I want to write a function that will rename the keys in dictionaries(or key tables) and cols in tables(or key tables), at all depthse.g. lowercase key,cols ... remove special chars ... etc

inspired but ridiculous, sloppy JSON files being fed into kdb

Something like this? (using your example, doing upper case)

 

q)a

     | ::

test | ab`c!1 2 3

test2| (1;“a”;DE`F!10 20 30)

test3| (2;“b”;fff;(1;"a";DEF!10 20 30);a_1b-2`c|3! 100 200 300)

test4| ((2;“b”;fff;(1;"a";DEF!10 20 30);a_1b-2c|3! [100 200 300]("tel:100%20200%20300"));+ghi!(1 2 3;abc;1 1.1 1.2);(+(,g)!,1 2 3)!+hi!(ab`c;1 1.1 1.2))

 

q){[f;x] $[.Q.qt x; f[cols x] xcol x;99=type x;f[key x]!.z.s[f] each value x;0h=type x; .z.s[f] each x;x]}[upper;a]

     | ::

TEST | AB`C!1 2 3

TEST2| (1;“a”;DE`F!10 20 30)

TEST3| (2;“b”;fff;(1;"a";DEF!10 20 30);A_1B-2`C|3! 100 200 300)

TEST4| ((2;“b”;fff;(1;"a";DEF!10 20 30);A_1B-2C|3! [100 200 300]("tel:100%20200%20300"));+GHI!(1 2 3;abc;1 1.1 1.2);(+(,G)!,1 2 3)!+HI!(ab`c;1 1.1 1.2))

 

 

If you expected dictionaries inside  rows of your table, you can modify the first cond to something like “f[cols x] xcol .z.s[f] each x”