Hello
I am trying to select an individual cell based on condition and insert it to a column in JSL.
For example:
I have this following table - I want to insert to the first row under column "value" the "score" value of the second row (11) because:
when looking on the first and second row:
home = home and y=y and x=x+1
Input:
| score | home | y | x | value |
| 10 | US | 1 | 1 | |
| 11 | US | 1 | 2 | |
| 10 | Canada | 1 | 1 | |
| 10 | US | 3 | 5 | |
Expected:
| score | home | y | x | value |
| 10 | US | 1 | 1 | 11 |
| 11 | US | 1 | 2 | |
| 12 | Canada | 1 | 1 | |
| 13 | US | 3 | 5 | |
Thanks
Most likely this isn't exactly what you want, but it does solve your example
Names Default To Here(1);
dt = New Table("Untitled",
Add Rows(4),
Compress File When Saved(1),
New Column("score", Numeric, "Continuous", Format("Best", 12), Set Values([10, 11, 10, 10])),
New Column("home", Character(16), "Nominal", Set Values({"US", "US", "Canada", "US"})),
New Column("y", Numeric, "Continuous", Format("Best", 12), Set Values([1, 1, 1, 3])),
New Column("x", Numeric, "Continuous", Format("Best", 12), Set Values([1, 2, 1, 5])),
New Column("value", Numeric, "Nominal", Format("", 16), Set Values([., ., ., .]))
);
Row() = 1;
If(:home == Lag(:home, -1) & :y == Lag(:y, -1) & :x + 1 == Lag(:x, - 1),
:value[Row()] = Lag(:score, - 1)
);