计数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提供两种解决我的问题的方法。 我将使用该脚本,因为我正在尝试为我的数据表创建创建完整的脚本,以便将来再次使用。
谢谢你!