unstack

unstack(t,vars,ivar) returns the unstacked table corresponding to the table t.
  • vars (string): column that will be used to fill the output table
  • ivar (string): the index column. Its (unique) values will define the output column names

Examples

>> t = table({'1-11';'2-11';'1-11';'2-11'}, {'A';'B';'B';'A'}, [5;10;15;7], 'VariableNames', {'date', 'id', 'price'})#

  date id         price 
  1-11  A             5 
  2-11  B            10 
  1-11  B            15 
  2-11  A             7 


>> U = unstack(t,'price','id')#

  date             A             B 
  1-11             5            15 
  2-11             7            10 
>> ticker = {'x1';'x1';'x2';'x2';'x3';'x3';'x3';'x3'}
date = {'20160731';'20160730';'20160731';'20160730';'20160731';'20160730';'20160729'; '20160729'}
value = [10;12;9;5;-2;17;-3;20]
t = table(ticker,date,value)
unstack(t,'value','ticker',[], @mean)#

      date            x1            x2            x3 
  20160729           NaN           NaN           8.5 
  20160730            12             5            17 
  20160731            10             9            -2 
 

See also

groupby | stack