-
How can I apply a function with ‘if’ to a table?
Hi! I’m trying to apply a function to a table. The basic idea is that if the 2 prices adds up to 0, then the new column gets 0, otherwise it gets the product of the 2 prices. However I encountered ‘type error.
The codes I wrote were?
//This is for creating t1 t1:([] TimeStamp:2018.01.01 2018.01.01 2018.01.02 2018.01.02;stock:`AAPL`AAPL`GOOGL`GOOGL;p1: 1 2 -2 3;p2: -1 1 2 0) //Then I define a function f:{[a;b] if[(a+b)=0;0;a*b]} //Then I apply t1:update r:f[p1;p2] from t1
However, it gave error message:
'type [4] f:{[a;b] if[(a+b)=0;0;a*b]}
^
How can I solve this problem?
Log in to reply.