How to convert a table to matrix

Hi All,

I have a table T like this:

T

date       s   n1 n2


2014.01.02 `a  1  0

2014.01.02 `b  -1 0

2014.01.03 `a  1  1

2014.01.03 `b  1  1

2014.01.04 `a  -1 2

2014.01.04 `b  -1 2

2014.01.05 `a  1  3

2014.01.05 `b  1  3

How to convert this table to a matrix M

M

daten2ab


2014.01.0201-1

2014.01.03111

2014.01.042-1-1

2014.01.05311

Thanks!

Roy

Hi,

There is code for this on code.kx.com

http://code.kx.com/wiki/Pivot

q)t

date s n1 n2

------------------

2014.01.02 a 1 0

2014.01.02 b -1 0

2014.01.03 a 1 1

2014.01.03 b 1 1

2014.01.04 a -1 2

2014.01.04 b -1 2

2014.01.05 a 1 3

2014.01.05 b 1 3

q)P:asc exec distinct s from t

q)exec P#(s!n1) by date, n2 from t

date n2| a b

-------------| -----

2014.01.02 0 | 1 -1

2014.01.03 1 | 1 1

2014.01.04 2 | -1 -1

2014.01.05 3 | 1 1

Regards,

Paul

Paul, it works! that’s what I need. Thank you.