I want to create a function that reads in a column, checks the number in each row on whether it is within spec, and output the passing count/total count/percentages.
This is what I have:
count_in_spec = Function( { col, lsl, usl },
a=0; //pass count
b=0; //all count
for( i = 1, i <= N Rows(col), i++,
if( col[i] >= lsl & col[i] <= usl, a++ );
if( not(ismissing(col[i])), b++ );
);
pctpass = 100*a/b;
pctfail = 100 - pctpass;
evallist({a, b, pctpass, pctfail});
);
dt0 = current data table();
colp = dt0:name("param") << get as matrix;
results = count_in_spec(colp, 0.15, 0.30 );
countpass = results[1];
countall = results[2];
pctpass = results[3];
pctfail = results[4];
While this works, I don't like the fact that I need to use "get as matrix". It's a bit clunky.
I would like a function that works simply by writing:
results = count_in_spec( "param name", lsl, usl);
How would I modify my function so it can work this way?