JSL腳本大家好,
我對JMP和編寫JSL腳本完全陌生,我需要幫助來構建案例邏輯:
我有一個表,其中一列為Status,我想在其中計算1的數量。它將在看到第一個“ 1”時開始計數,並繼續計數直到最後一個,並在最後一次出現1時輸出最終計數。並且在下一行看到“ 0”後,應再次重置計數器並開始尋找“ 1”。

如果您能幫助我,我將不勝感激。
阿比
回复:JSL腳本可以做到這一點
Names default to here(1);
m = [0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0];
dt = new table("Test",
<< New Column("Status", <<SET values=""></SET>回复:JSL腳本names default to here(1);
// create the table
m = [0,0,0,0,0,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0];
dt = new table("Test",
new column("Status", set values(m));
);
// create the empty status column
dt << new column("Output");
// iterate over each row of the table
result = 0; // counter for consecutive 1's
for (i=1,i<=nrows(dt),i++,
// apply the logic the way
// that you would think it
value = dt:Status[i]; // i'th row of Status column table referenced by dt
if (value==0,
dt:Output[i] = 0;
result = 0;
,
result = result + 1;
dt:Output[i] = result;
)
);回复:JSL腳本感謝您的幫助。邏輯非常簡單明了,對您有很大幫助。再次感謝。