大家好!
我需要計算“到達延遲”列上負數的數量或百分比。
JMP 的選單操作和公式中似乎沒有找到此功能。
excel中有一個=countif(,"<0")可以快速完成。
JMP想要使用循環?
dt = Open( "$SAMPLE_DATA/Airline Delays.jmp" );

吉姆的回答很好;這裡還有兩個避免建立列但具有不同副作用的方法:
dt = Open( "$sample_data/big class.jmp" );
// using table subscripts, suitable for use in a column formula.
// As Constant calculates the result once, not for every row.
As Constant( N Rows( Loc( dt[0, "age"] < 15 ) ) ); // 27
// using row selection, suitable for JSL programs. Avoids a temporary
// matrix but does change the selection state of the table.
dt << selectwhere( age < 15 );
N Rows( dt << getselectedrows ); // 27
您的選擇在一定程度上取決於您是在列公式中還是在 JSL 程式中使用它; JMP 新增了 As Constant 函數(主要)是為了支援需要進行昂貴計算的列公式。 如果沒有它,JMP 就會計算每一行的行數,導致 N^2 效能問題。
解釋第一個範例:dt[0,"age"] 從表格中傳回一個矩陣 (郵政)。 0 表示所有行。 將此矩陣與 < 15 進行比較將傳回包含 0 和 1 結果的矩陣。 Loc([ 1 0 1 0]) 傳回非零(真)結果位置的較小矩陣。 NRows 或 NItems 報告元素的數量。 因為如果您在變數中捕獲答案,則 JSL 程式中不需要 Constant。