列全体の条件付きカウントかなりの数の列(> 100)を持つテーブルがあります。 1より大きい行の列数をカウントする列を作成しようとしています。 それを行うための式をどのように書くのですか? 以下は、テーブルの例の小さな写真です。
これが、スタンドアロンのJSLスクリプトではなく、テーブルにドロップできる単なる数式であることが望ましいでしょう。
データ表スクリプティングRe:列全体の条件付きカウントこれが1つの方法です:
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)));Re: 列間の条件付きカウントデータの更新を容易にするために、入力列の 1 つ (ここではheight ) をダミーとして列の式に追加できます。その後、JMP はこの列を監視します。更新をトリガーするには、この列の値を編集するだけです。
さらに、データテーブル「access」と列定義を定数として配置することもできます。
Open( "$SAMPLE_DATA/Big Class.jmp" );
New Column( "values > 60",
Formula(
As Constant(
dt = Current Data Table();
//cols = Index(4,5);
cols = {"height", "weight"};
);
:height;
Sum( dt[Row(), cols] > 60 );
)
);