こんにちは、次のような課題があり、スクリプト作成に問題があります。
私の開始データテーブルは以下のようになります。 基準としてcol2 =0から開始してXiを逆方向に乗算し、新しい値を新しい列に入れたいと思います。
列1 列2
X10
X2 y2
X3 y3
…
Xn yn
XX10
XX2年2月
…。
XXn yyn
…。
…。
最終的なデータテーブルは次のようになります。
列1 列2 列3
X1 0 Xn*Xn-1*……X3*X2*X1
X2 y2 Xn*Xn-1*…..X3*X2
X3 y3 Xn*Xn-1*….*X3
…
Xn yn Xn
XX1 0 XXn*XXn-1*…..XX2*XX1
XX2 yy2 XXn*XXn-1*…..XX2
…。
XXn yyn XXn
…。
…。
誰か手伝ってくれませんか? 非常に高く評価!
データが逆であれば、必要な計算は非常に簡単に実行できるため、その考え方を使用して値を計算する小さなスクリプトを次に示します。
names default to here(1);
// create the sample table
dt = New Table( "example",
Add Rows( 10 ),
New Column( "col1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 2, 3, 2, 4, 5, 6, 7, 8, 9] ),
Set Display Width( 48 )
),
New Column( "col2",
Character( 1 ),
"Nominal",
Set Values( {"x", "x", "x", "y", "y", "y", "y", "z", "z", "z"} ),
Set Display Width( 45 )
)
);
// JSL to create the column you want
// create a new column to preserve the order of the data
dt << new column("origRow", formula(row()));
dt:origRow << delete formula;
// Reverse the order of the data
dt << sort(by(:origRow), order(descending), replace table(1));
// create the new column
dt << new column( "col3", formula(
If( Row() == 1, x = :col1 );
If( Lag( :col2 ) != :col2,
x = :col1,
x = x * :col1
);
x;
));
// Since the formula is dependent on the order of the data, the formula needs
// to be removed and the values set to static values
dt:col3 << delete formula;
// reorder the data table back to the original order and delete the origRow column
dt << sort(by(:origRow), order(ascending), replace table(1));
dt << delete columns(:origRow);
そして、これはソートせずに新しい列を作成する JSL の一部です。
Names Default To Here( 1 );
// create the sample table
dt = New Table( "example",
Add Rows( 10 ),
New Column( "col1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 2, 3, 2, 4, 5, 6, 7, 8, 9] ),
Set Display Width( 48 )
),
New Column( "col2",
Character( 1 ),
"Nominal",
Set Values( {"x", "x", "x", "y", "y", "y", "y", "z", "z", "z"} ),
Set Display Width( 45 )
)
);
// create the new column
dt << New Column( "col3b" );
:col3b[N Rows( dt )] = :col1[N Rows( dt )];
For( i = N Rows( dt ) - 1, i >= 1, i--,
If( :col2[i + 1] != :col2[i],
:col3b[i] = :col1[i],
:col3b[i] = :col3b[i + 1] * :col1[i]
)
);
こんにちは、ジム@txnelson
これは実際には、より小さなテーブル (つまり、数千行) で機能しました。 ありがとう。
私が抱えている「新たな」問題は、データテーブルが非常に大きいことです。 新しい列に数式を埋め込んで「適用」をクリックすると、プログラムがハングし、終了するには jmp を強制終了する必要がありました。
数式の上にカーソルを置くと、「現在のデータ テーブル」に関する警告メッセージが表示されます。
「Current data table() には副作用があるため、通常、数式内で使用するのは不適切です。 これが必要な場合は、式での実行を防ぐために expr または eval を使用できます....」
私のスクリプトスキルは非常に限られています。 この件に関してさらにご協力いただきありがとうございます。
よろしく、
定恵
@txnelson書きました:
新しい式は次のとおりです。前の式と同じ方法ですが、各グループの開始点と終了点を見つける必要があるだけです。
If( Row() == 1,
curCol = :col2;
end = Max( Current Data Table() << get rows where( :col2 == curCol ) );
x = :col1;
,
:col2 != curCol;
curCol = :col2;
end = Max( Current Data Table() << get rows where( :col2 == curCol ) );
x = :col1;
);
For( i = Row() + 1, i <= end, i++,
x = x * :col1[i]
);
x;
新しい式は次のとおりです。前の式と同じ方法ですが、各グループの開始点と終了点を見つける必要があるだけです。
If( Row() == 1,
curCol = :col2;
end = Max( Current Data Table() << get rows where( :col2 == curCol ) );
x = :col1;
,
:col2 != curCol;
curCol = :col2;
end = Max( Current Data Table() << get rows where( :col2 == curCol ) );
x = :col1;
);
For( i = Row() + 1, i <= end, i++,
x = x * :col1[i]
);
x;

こんにちは、ジム@txnelson
お返事をありがとうございます。
いいえ、列名は変わりません。 与えられたとおり、col1、col2 のままになります。Col2 で指定された同じ値に対して後方乗算を行う新しい列 (col3) を追加したいと考えています。 次の表で私の必要性を示します。助けていただけますか?
列1 列2 列3
1×6 (つまり、1×2×3)
2×6(つまり2×3)
3×3(つまり3)
2 y 240 (つまり 2x4x5x6)
4 y 120 (つまり 4 x 5 x6)
5 y 30 (つまり 5 x 6)
6 y 6 (つまり 6)
7 z 504 (つまり 7x8x9)
8 z 72 (つまり 8x9)
9z9
ありがとう!
グループ化変数を見逃したため、投稿を削除しました。 私のアプローチはこのシナリオでは機能しません。
3 セットの列がわかりません。データテーブルの途中で列名を変更しているように見えますが、これは JMP では機能しません。この表の形式は Excel スプレッドシートからのものですか?
以下は、次のようなデータテーブルに対して必要なことを実行する簡単な数式です。

データ表を添付しました。
使用される式は次のとおりです。
x = :col2[Row()];
If( Row() < N Rows( Current Data Table() ),
For( i = Row() + 1, i <= N Rows( Current Data Table() ), i++,
x = x * :col2[i]
)
);
x;
これと同じ考え方は、乗算を再開する必要があるデータ テーブル内に複数の場所がある場合にも使用できます。いつ再開し、いつ終了するかを特定する必要がある。