transpose

Syntax

transpose(X)

alias: flip(X)

Arguments

X is a tuple, matrix, table, or dictionary.

Details

If X is a tuple: all elements of the tuple must have the same length. Return a tuple of the same length as each element of X. The n-th element of the result is a vector composed of the n-th element of each element of X.

If X is a matrix: return the transpose of X.

If X is a table: convert X into an ordered dictionary. The dictionary keys are column names. Each dictionary value is a vector of the corresponding column.

If X is a dictionary: convert X into a table. The dictionary keys must be of STRING type, and dictionary values must be vectors of the same length. The columns names of the table are the dictionary keys, and each column is the corresponding dictionary value.

Examples

Example 1: transpose of a tuple:

$ x=(`A`B`C,1 2 3);
$ x.transpose();
(("A",1),("B",2),("C",3))

Example 2: transpose of a matrix:

$ x=1..6 $ 3:2;
$ x;

#0

#1

1

4

2

5

3

6

$ transpose x;

#0

#1

#2

1

2

3

4

5

6

Example 3: convert a table into a dictionary:

$ timestamp = [09:34:07,09:36:42,09:36:51,09:36:59,09:32:47,09:35:26,09:34:16,09:34:26,09:38:12]
$ sym = `C`MS`MS`MS`IBM`IBM`C`C`C
$ price= 49.6 29.46 29.52 30.02 174.97 175.23 50.76 50.32 51.29
$ qty = 2200 1900 2100 3200 6800 5400 1300 2500 8800
$ t = table(timestamp, sym, qty, price);
$ t;

timestamp

sym

qty

price

09:34:07

C

2200

49.6

09:36:42

MS

1900

29.46

09:36:51

MS

2100

29.52

09:36:59

MS

3200

30.02

09:32:47

IBM

6800

174.97

09:35:26

IBM

5400

175.23

09:34:16

C

1300

50.76

09:34:26

C

2500

50.32

09:38:12

C

8800

51.29

$ transpose(t);
timestamp->[09:34:07,09:36:42,09:36:51,09:36:59,09:32:47,09:35:26,09:34:16,09:34:26,09:38:12]
sym->[C,MS,MS,MS,IBM,IBM,C,C,C]
qty->[2200,1900,2100,3200,6800,5400,1300,2500,8800]
price->[49.6,29.46,29.52,30.02,174.97,175.23,50.76,50.32,51.29]

Example 4: convert a dictionary into a table:

$ z=dict(`id`val,[`a`b`c,1 2 3]);
$ z;
val->[1,2,3]
id->[a,b,c]

$ transpose(z);

val

id

1

a

2

b

3

c