こんにちは、
新しいウィンドウ() を表示して、ユーザーにリスト ボックス() のデータ テーブルからいくつかのカテゴリ ファクターを選択するように要求しようとしています。
次の点を強調することで、この選択についてさらに詳しく説明したいと思います。
- 各要因のレベル数
- 各要素の列内の空白セルの割合を示す色
私が達成したいことの例を添付します。
次のスクリプトでは、各要素の情報を計算し、リスト「値」を入力します。
しかし、これらの情報を使ってリストボックス()のデザインにどうアプローチすればいいのか分かりません。
ご協力いただきありがとうございます
- 説教者

Names Default To Here( 1 );
clear symbols();
Deletesymbols();
dt = New Table( "RawData",
Add Rows( 20 ),
New Column("factor1", Character, set values( {"A","A","A","A","A","A","A","B","B","B","B","B","B","C","C","C","C","C","C","C"})),
New Column("factor2", Character, set values( {"T0","DROP1","DROP2","DROP3","DROP4","DROP5","DROP6","T0","DROP1","DROP2","DROP3","DROP4","DROP5","T0","DROP1","DROP2","DROP3","DROP4","DROP5", "DROP6"})),
New Column("factor3", Character, set values({"1","1","1","2","2","", ,"","","" ,"" ,"", "","3","3","3","3"}) ),
New Column("factor4", Character, set values({"a","a","a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b" , "b", "b", "b", "b"}) );
);
RawDataCol = dt << get column names ("character");
show (RawDataCol);
for(i=1, i<= N items (RawDataCol), i++,
FactorSummary = {};
Eval(Eval Expr(FactorSummary = Column(dt, Expr(char(RawDataCol[i]))) << get values));
//show (FactorSummary);
//find cell count (non empty)
Eval(Eval Expr(For( j = N Items(FactorSummary), j > 0, j--,
If( FactorSummary[j] == "",
Remove From( FactorSummary, j, 1 )
)
)));
//Find number of level within a factor (non empty)
Eval(Eval Expr(Summarize( LevelSummary = by(Column(dt, Expr(char(RawDataCol[i])))) )));
Eval(Eval Expr(For( j = N Items(LevelSummary), j > 0, j--,
If( LevelSummary[j] == "",
Remove From( LevelSummary, j, 1 )
)
)));
//show (LevelSummary);
Eval(Eval Expr(Value = {Expr(RawDataCol[i]), Expr(N items(LevelSummary)), Expr(N items (FactorSummary) / N row(dt))}));
show (Value);
);
MainWindow = New Window( "Select Factors",
<<MODAL></MODAL>リストボックスは最も柔軟な表示ボックスではありません。txnelson の意見に賛成です。テーブルボックスを使用できると思います。以下は 1 つの例です。
Names Default To Here(1);
dt = New Table("RawData",
Add Rows(20),
New Column("factor1",
Character,
set values({"A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B", "C", "C", "C", "C", "C", "C", "C"})
),
New Column("factor2",
Character,
set values(
{"T0", "DROP1", "DROP2", "DROP3", "DROP4", "DROP5", "DROP6", "T0", "DROP1", "DROP2", "DROP3", "DROP4", "DROP5", "T0", "DROP1", "DROP2",
"DROP3", "DROP4", "DROP5", "DROP6"}
)
),
New Column("factor3", Character, set values({"1", "1", "1", "2", "2", "", , "", "", "", "", "", "", "3", "3", "3", "3"})),
New Column("factor4", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"}))
);
cols = dt << get column names("character", "string");
factors = {};
factor_counts = {};
missing_perc = {};
For Each({colname}, cols,
Summarize(dt, uniq = by(Eval(colname)));
Remove From(uniq, Contains(uniq, ""));
nvalues = Col Number(Column(dt, colname));
Insert Into(factors, colname);
Insert Into(factor_counts, N Items(uniq));
Insert Into(missing_perc, (nvalues)/ N Rows(dt));
);
dt_factors = New Table("Demo",
Add Rows(N Items(factors)),
New Column("Factor", Character, Nominal, Values(factors)),
New Column("Count", Numeric, Continuous, Values(factor_counts)),
New Column("% Non-missing", Numeric, Continuous, Format("Percent", 12, 3), Values(missing_perc)),
Invisible
);
orange_rows = dt_factors << Get Rows Where(:"% Non-missing"n < 0.5);
yellow_rows = dt_factors << Get Rows Where(0.5 < :"% Non-missing"n < 0.9);
For Each({colname}, dt_factors << Get Column Names("String"),
Column(dt_factors, colname) << Color Cells("Green");
Column(dt_factors, colname) << Color Cells("Orange", orange_rows);
Column(dt_factors, colname) << Color Cells("Yellow", yellow_rows);
);
nw = New Window("Select",
H List Box(
Panel Box("Select factors to run the analysis",
bb = dt_factors << get as report
),
Panel Box("Actions",
Lineup Box(N Col(1),
Button Box("OK",
tb = bb << child;
sel_rows = tb << get selected rows;
show(sel_rows, tb[1][sel_rows]);
),
Button Box("Cancel", << Set Function(function({this}, this << close window))),
)
)
)
);
Close(dt_factors, no save);

こんにちは、ジャーモさん
この解決策は非常に気に入っています (提案してくれた Jim にも感謝します)。
考慮する必要があることの 1 つは、要因が数十個ある可能性があるという事実です。
Table Box() の高さを固定する方法はありますか?
たとえば、表示される行は 5 行のみで、ユーザー入力 (ラジオ ボックス、チェック ボックスなど) をさらに追加するために、下にスクロールして高さを固定できます。
以下は、より多くの行があり、それらすべてが表示されているテーブルボックス()の例です(より多くの要因で問題になります)
どうもありがとう
Names Default To Here(1);
dt = New Table("RawData",
Add Rows(20),
New Column("factor1",
Character,
set values({"A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B", "C", "C", "C", "C", "C", "C", "C"})
),
New Column("factor2",
Character,
set values(
{"T0", "DROP1", "DROP2", "DROP3", "DROP4", "DROP5", "DROP6", "T0", "DROP1", "DROP2", "DROP3", "DROP4", "DROP5", "T0", "DROP1", "DROP2",
"DROP3", "DROP4", "DROP5", "DROP6"}
)
),
New Column("factor3", Character, set values({"1", "1", "1", "2", "2", "", , "", "", "", "", "", "", "3", "3", "3", "3"})),
New Column("factor4", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factor5", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factor6", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factor7", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factor8", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factor9", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factor10", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factor12", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factor13", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factorA", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factorB", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factorB1", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factorC", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factorD", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factor69", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factor67", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factor47", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"})),
New Column("factor56", Character, set values({"a", "a", "a", "", "", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b"}))
);
cols = dt << get column names("character", "string");
factors = {};
factor_counts = {};
missing_perc = {};
For Each({colname}, cols,
Summarize(dt, uniq = by(Eval(colname)));
Remove From(uniq, Contains(uniq, ""));
nvalues = Col Number(Column(dt, colname));
Insert Into(factors, colname);
Insert Into(factor_counts, N Items(uniq));
Insert Into(missing_perc, (nvalues)/ N Rows(dt));
);
dt_factors = New Table("Demo",
Add Rows(N Items(factors)),
New Column("Factor", Character, Nominal, Values(factors)),
New Column("Count", Numeric, Continuous, Values(factor_counts)),
New Column("% Non-missing", Numeric, Continuous, Format("Percent", 12, 3), Values(missing_perc)),
Invisible
);
orange_rows = dt_factors << Get Rows Where(:"% Non-missing"n < 0.5);
yellow_rows = dt_factors << Get Rows Where(0.5 < :"% Non-missing"n < 0.9);
For Each({colname}, dt_factors << Get Column Names("String"),
Column(dt_factors, colname) << Color Cells("Green");
Column(dt_factors, colname) << Color Cells("Orange", orange_rows);
Column(dt_factors, colname) << Color Cells("Yellow", yellow_rows);
);
nw = New Window("Select",
H List Box(
Panel Box("Select factors to run the analysis",
bb = dt_factors << get as report
),
Panel Box("Actions",
Lineup Box(N Col(1),
Button Box("OK",
tb = bb << child;
sel_rows = tb << get selected rows;
show(sel_rows, tb[1][sel_rows]);
),
Button Box("Cancel", << Set Function(function({this}, this << close window))),
)
)
)
);
Close(dt_factors, no save);