你好,
我是 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"
);
)
);