計數jsl中的字符列我有一個包含幾個數據列的數據表,這些數據列具有二進制0/1響應(字符,標稱值)。 我想創建一個新列(數字,連續),在其中計算這些列中“ 1”的實例。
有人可以幫助我創建腳本來創建此列嗎? 我覺得這應該很容易,但是我遇到了障礙。 我必須將字符列轉換為數字/連續列並求和公式嗎?謝謝!
樣表
| 感染(字符,名義上) | 血凝塊(字符,標稱) | 手術(字符,名義上) | 新欄: 並發症數(數字,連續) |
| 0 | 1個 | 1個 | 2個 |
1個 | 1個 | 1個 | 3 |
| 1個 | 0 | 0 | 1個 |
| 0 | 1個 | 0 | 1個 |
腳本編寫回复:計數jsl中的字符列您只需要一個公式。

這是結果。

回复:計數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 )
);回复:計數jsl中的字符列多虧了@馬克貝利和@txnelson提供兩種解決我的問題的方法。 我將使用該腳本,因為我正在嘗試為我的數據表創建創建完整的腳本,以便將來再次使用。
謝謝你!