jslで文字列を数えるバイナリ 0/1 応答 (文字、公称) を持つ複数のデータ列を含むデータ テーブルがあります。 これらの列の「1」のインスタンスをカウントする新しい列 (数値、連続) を作成したいと考えています。
この列を作成するスクリプトの作成を手伝ってくれる人はいますか? これは簡単なはずですが、障害物にぶつかっています。 文字列を数値/連続列に変換し、合計式を実行する必要がありますか?ありがとうございました!
例の表
| 感染症(性格、名目) | 血栓(性格、公称) | 手術(性格、公称) | 新しい列: 合併症の数(数値、連続) |
| 0 | 1 | 1 | 2 |
1 | 1 | 1 | 3 |
| 1 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 |
スクリプティングRe:jslで文字列を数える両方のおかげで@マークベイリーと@txnelson私の問題に2つのアプローチを提供してくれて。 将来再び使用できるように、データ テーブル作成用の完全なスクリプトを作成しようとしているので、このスクリプトを使用します。
ありがとう!
Re:jslで文字列を数える@マークベイリー良い解決策を提供した
問題を解決する別の方法があります
Names Default To Here( 1 );
dt = Current Data Table();
charNames = dt << get column names( character );
// convert char columns to numeric
For( i = 1, i <= N Items( charNames ), i++,
Column( dt, charNames[i] ) << data type( numeric )
);
// Create the jsl required to sum all of the specified columns
theExpr = "dt << new column(\!"number of complications\!", formula(sum(" ||
Substr( Char( charnames ), 2, Length( Char( charNames ) ) - 2 ) || "));";
// Execute the line of code created
Eval( Parse() );
// Delete the formula leaving the static values
Column( dt, "number of complications" ) << delete formula;
// Convert the binary columns back to character
For( i = 1, i <= N Items( charNames ), i++,
Column( dt, charNames[i] ) << data type( character )
);Re:jslで文字列を数える必要なのは式だけです。

これが結果です。
