Jms
Jms

Reputation: 159

(q/kdb+) Split string column into float columns

What is the best way to split the string column b

t:([]a:3,4,5;b:("45 | 37 <> 5 | 6";"67 | 981 <> 50 | 7";"1 | 71 <> 15 | 8"))

a   b
3   "45 | 37 <> 5 | 6"
4   "67 | 981 <> 50 | 7"
5   "1 | 71 <> 15 | 8"

to get this

a   b                     c     d    e   f
3   "45 | 37 <> 5 | 6"    45    37   5   6
4   "67 | 981 <> 50 | 7"  67    981  50  7
5   "1 | 71 <> 15 | 8"    1     71   15  8

I was trying something like

update c:"F"${2#x}each b,d:"F"${4_7#x}each b from t

it works in parts, but it does not seems the right way.

Upvotes: 4

Views: 1309

Answers (1)

terrylynch
terrylynch

Reputation: 13572

You could try something like this:

q)t,'flip exec `c`d`e`f!("H H H H";" ")0:b from t
a b                    c  d   e  f
----------------------------------
3 "45 | 37 <> 5 | 6"   45 37  5  6
4 "67 | 981 <> 50 | 7" 67 981 50 7
5 "1 | 71 <> 15 | 8"   1  71  15 8

Assumes the numbers are always space separated and that there are always unwanted symbols in between.

Upvotes: 3

Related Questions