计算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中的字符列您只需要一个公式即可。

这是结果。
