꽤 많은 열(>100)이 있는 테이블이 있습니다. 1보다 큰 행의 열 수를 계산하는 열을 만들려고 합니다. 그렇게 하려면 공식을 어떻게 작성해야 합니까? 아래는 예제 테이블의 작은 그림입니다.
이것이 독립형 JSL 스크립트가 아닌 테이블에 놓을 수 있는 공식이라면 더 좋을 것입니다.
한 가지 방법은 다음과 같습니다.
NamesDefaultToHere(1);
// Build a table
nr = 20; // Number of rows
nc = 10; // Number of columns
dt = AsTable(J(nr, nc, RandomNormal(1, 1)));
dt << setName("Above and Below One");
// Find out what columns are in the table
cols = dt << getColumnNames("String");
// Build an expression to be used as the formula:
// Sum the results of an 'if' clause for each column that exists
form = Expr(Add());
for(c=1, c<=NItems(cols), c++,
ifClause = Expr(If(columnTBD > 1, 1, 0));
SubstituteInto(ifClause, Expr(columnTBD), Parse(":"||cols[c]));
InsertInto(form, NameExpr(ifClause));
);
// Inspect the resulting formula
Print(form);
// Add the formula column
fc = dt << NewColumn("Count Above One", Numeric, Ordinal, Formula(NameExpr(form)));