計算jsl中的字元列我有一個資料表,其中包含多個帶有二進位 0/1 回應(字元、標稱)的資料列。 我想建立一個新列(數字,連續),在其中計算這些列中「1」的實例。
有人可以幫我創建一個腳本來創建此專欄嗎? 我覺得這應該很容易,但我遇到了障礙。 我是否必須將字元列轉換為數字/連續列並執行求和公式?謝謝你!
範例表
| 感染(字符,名義) | 血塊(特徵,名義) | 手術(性質、名義) | 新專欄: 併發症數量(數字,連續) |
| 0 | 1 | 1 | 2 |
1 | 1 | 1 | 3 |
| 1 | 0 | 0 | 1 |
| 0 | 1 | 0 | 1 |
進階統計建模自動化和腳本編寫消費者與市場研究大規模客製化可靠度分析回覆:計算jsl中的字元列感謝雙方@馬克貝利和@tx尼爾森為我的問題提供了兩種方法。 我將使用該腳本,因為我正在嘗試建立一個完整的腳本以便將來再次使用我的資料表建立。
謝謝你!
回覆:計算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中的字元列您只需要一個公式。

這是結果。
