I used Color Out of Spec Values() to color spec fails in my measurement data. I have multiple columns with measurement data and the out of spec values for each column get colored according to the spec for each parameter column.
For each parameter column I want to create an adjacent column which assigns a "1" when the cell is colored otherwise "0".
How to achieve this via JSL?
This gives idea how you can handle the situation for one column
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
a = {1, 3, 5};
b = {2, 4, 6};
c = {7, 8, 9};
:height << color cells({{"Red", a}, {"blue", b}, {"yellow", c}});
:weight << color cells({{"Red", a}});
:age << color cells({{"Red", a}, {"blue", b}});
get_colored_cells = Function({dt, colname}, {Default Local},
colscript = Column(dt, colname) << Get Script;
l = Substitute(Name Expr(colscript), Expr(New Column()), List());
colored_cells = {};
Try(
colors = l["Color Cells"];
If(Type(colors[1]) == "List",
jmptrickery = 1;
,
jmptrickery = 0;
);
For Each({color}, colors,
If(jmptrickery,
Insert Into(colored_cells, color[2]);
,
Insert Into(colored_cells, color);
);
);
);
return(Matrix(colored_cells));
);
colname = "age";
// for single column
rows = J(1, N Rows(dt), 0);
colored_rows = get_colored_cells(dt, colname);
rows[colored_rows] = 1;
dt << New Column("result", Numeric, Nominal, Values(rows));
you can then create additional column to color each column when you loop over them