跨列條件計數我有一個包含相當多列(> 100)的表格。 我正在嘗試建立一個列來計算一行中大於 1 的列數。 我該如何編寫一個公式來做到這一點? 下面是範例表格的小圖片。
如果這只是一個可以放入表中的公式而不是獨立的 JSL 腳本,那就更好了。
自動化和腳本編寫回覆:跨列的條件計數此公式希望您的「計算」列成為資料表中的最後一個列,並且必須在新增公式之前建立它。 此外,這不會像普通公式一樣更新,因此您必須打開公式並按“應用”:
Sum(Current Data Table()[Row(), Index(1, N Cols(Current Data Table()) - 1)] > 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)));回覆:跨列的條件計數為了方便資料更新,您可以將輸入列之一(此處: 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 );
)
);