你好,
我是 JMP 脚本编写的新手。 我正在编写一个脚本来选择包含单词“Censor”的多个列并更新缺失值。下面是一组示例数据。 我列出了三列审查员 A、审查员 B 和审查员 C。但在现实世界中,列数每次都可能不同。所以我必须选择包含作品“Censor”的列,然后用“S”更新所有缺失值。 我可以在 JSL 中这样做吗? 我仍在学习脚本编写,但在 JMP 帮助中找不到方法。
| 审查员A | 审查员B | 审查员C |
| F | | F |
| F | F | |
| F | | |
| | | F |
| | F | F |
| F | | |
这是对我的初始脚本的修改,以执行我认为您想要的操作......
Names Default To Here( 1 );
// Create a sample data table
dt = New Table( "Example 2",
Add Rows( 6 ),
New Column( "Censor A",
Character,
"Nominal",
Set Values( {"F", "F", "F", "", "", "F"} )
),
New Column( "Censor B",
Character,
"Nominal",
Set Values( {"", "F", "", "", "F", ""} )
),
New Column( "Censor C",
Character,
"Nominal",
Set Values( {"F", "", "", "F", "F", ""} )
),
New Column( "Setting Column",
Character,
"Nominal",
Set Values( {"Z", "X", "Y", "W", "P", "Q"} )
)
);
// Get the names of all of the columns
colNames = dt << get column names( string );
// Loop across all columns and if a Censor column
// then process
For( i = 1, i <= N Items( colNames ), i++,
If( Left( colNames[i], 6 ) == "Censor",
dt << select where( As Column( colNames[i] ) == "" );
// If blanks are found then process
rowMat = dt << get selected rows;
If( N Rows( rowMat ) > 0,
For( k = 1, k <= N Rows( rowMat ), k++,
Column( colNames[i] )[rowMat[k]] = :Setting Column[rowMat[k]]
)
);
)
);这是一个简单的脚本,可以完成填充缺失的单元格
Names Default To Here( 1 );
// Create a sample data table
dt = New Table( "Example",
Add Rows( 6 ),
New Column( "Censor A",
Character,
"Nominal",
Set Values( {"F", "F", "F", "", "", "F"} )
),
New Column( "Censor B",
Character,
"Nominal",
Set Values( {"", "F", "", "", "F", ""} )
),
New Column( "Censor C",
Character,
"Nominal",
Set Values( {"F", "", "", "F", "F", ""} )
)
);
// Get the names of all of the columns
colNames = dt << get column names( string );
// Loop across all columns and if a Censor column
// then process
For( i = 1, i <= N Items( colNames ), i++,
If( Left( colNames[i], 6 ) == "Censor",
dt << select where( As Column( colNames[i] ) == "" );
// If blanks are found then process
If( N Rows( dt << get selected rows ) > 0,
As Column( colNames[i] )[dt << get selected Rows] = "S"
);
)
);