選擇重複的行條目,儲存其索引,然後建立一個不包含重複行的新清單。你好。
這是此連結中問題的後續: 已解決:從選擇位置獲取值 - JMP 用戶社群。在本次討論的最後(在提供的連結中),有一種 jsl 可以選擇某些行並使用 show() 函數列印它們。在另一篇文章中(我丟失了它的連結),有一種方法可以使用 Select Duplicated Row() 函數選擇重複的行,然後刪除它們。
我的目標是選擇重複的行,然後取得表格中選定列的索引。例如,我想在大類表中找到年齡列的重複條目。
第二個目標是建立一個只包含唯一行的新列,而不刪除重複的行。
任何指導表示讚賞。
dt_limit = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt_limit:age << Select Duplicate Rows( Match (:age, :age ) );
Group1List = (dt_limit:age[dt_limit << get selected rows]);
theCount = N Rows( dt << get selected rows);
Show( Group1List);
自動化和腳本編寫基礎資料分析與建模資料存取回覆:選擇重複的行條目,儲存其索引,然後建立一個不包含重複行的新清單。謝謝@Jed_Campbell 。這很好,非常感謝!
我正在嘗試將該列捕獲到列表中以進行進一步操作。你能幫我嗎?謝謝!
回覆:選擇重複的行條目,儲存其索引,然後建立一個不包含重複行的新清單。新增在腳本末尾的這一行應該會將該列放入清單中:
future_list = as list (dt_limit:Unique << Get Values);
回覆:選擇重複的行條目,儲存其索引,然後建立一個不包含重複行的新清單。謝謝@Jed_Campbell 。它工作得很好。
我目前遇到的另一個問題是,如果我不是只有一列(即年齡),而是有一個列列表(即[年齡、身高、體重等])怎麼辦?程式碼會如何改變?我嘗試使用列和 eval 的組合來將清單條目作為列獲取。我知道下面的程式碼確實有效,但我如何修改它以適用於任何列列表。會有類似 As column (ListOfTargetCol[i])[i] ); 的內容或:(ListOfTargetCol[i])[i]);意味著 jmp 將取得清單的第 i 個條目,然後取得該列(列)的第 i 個條目?我是 jsl 的新手,不確定它的結構如何。請告知如何克服這個問題。
作為參考,我使用與上面提供的程式碼類似的程式碼,並嘗試添加如下內容:我也很好奇,如果它是像下面這樣的字串名稱列表,它是否會有所不同。多謝!
ListOfTargetCol = { age, height, weight};
StringOfTargetCol = { "age", "height", "weight"};
... dt_limit:Unique[i] = dt_limit:( As coulmn(ListOfTargetCol[1])) [i]...
回覆:選擇重複的行條目,儲存其索引,然後建立一個不包含重複行的新清單。您正在尋找這樣的東西嗎?可能有更優雅的方法來完成它,但這是一種僅使用第一個唯一行創建新列的方法。
dt_limit = Open( "$SAMPLE_DATA/Big Class.jmp" );
dt_limit << Select Duplicate Rows( Match (:age ) );
Group1List = (dt_limit << get selected rows);
theCount = N Items (Group1List);
//create a new column that has only the unique rows without deleting the duplicated row
dt_limit << Invert Row Selection;
UniqueList = dt_limit << Get Selected Rows;
dt_limit << new column ("Unique");
for each ({i}, UniqueList,
dt_limit:Unique[i] = dt_limit:age[i]
);回覆:選擇重複的行條目,儲存其索引,然後建立一個不包含重複行的新清單。如果您不需要選擇,您也可以使用公式/摘要(或許多其他選項)
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// Option1
new_col = dt << New Column("R1", Numeric, Continuous, Formula(
If(Row() == Col Min(Row(), :age), :age, .)
));
dt << Run Formulas;
new_col << Delete Formula;
// Option2
dt << New Column("Row", Numeric, "Continuous", Formula(Row()));
dt_summary = dt << Summary(
Group(:age),
Min(:Row),
Freq("None"),
Weight("None"),
statistics column name format("column"),
Link to original data table(0)
);
dt_summary << Delete Columns("N Rows");
Column(dt_summary, 1) << Set Name("R2");
dt << Update(With(dt_summary), Match Columns(:Row = :Row));
Close(dt_summary, no save);

回覆:選擇重複的行條目,儲存其索引,然後建立一個不包含重複行的新清單。謝謝@jthi 的幫忙!兩種解決方案都運作良好,但我仍然對應該使用的語法感到困惑。
In the loop below, we have the dt:age[i] which iterates through the "age" column in the dt_limit loop. <BR />What if I want to have more than one column to iterate through.<BR /><BR /> The only solution I can find (and works with no error) is to copy past the loop for <BR />all the needed columns i.e. age, height, ..etc. It is just not efficient and will not work for a large number of columns. <BR /><BR />Any suggestions would be appreciated.
<BR />
for each ({i}, UniqueList,
dt_limit:Unique[i] = dt_limit:age[i]
);回覆:選擇重複的行條目,儲存其索引,然後建立一個不包含重複行的新清單。我不太確定你想做什麼。您可以將更多列新增至 Col Min 作為 byvars
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// Option1
new_col = dt << New Column("R1", Numeric, Continuous, Formula(
If(Row() == Col Min(Row(), :age, :sex), :age, .)
));
dt << Run Formulas;
new_col << Delete Formula;

列最小值(名稱, )
回覆:選擇重複的行條目,儲存其索引,然後建立一個不包含重複行的新清單。謝謝@jthi 。真的。我可以按照您上面的建議添加更多列。但是,我正在嘗試概括該解決方案。我想做的是獲取用戶輸入以評估哪些列。將它們放在一個列表中。然後,評估所有這些。例如,使用者只能選擇年齡和身高。我需要程式碼盡可能靈活。
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
// Option1
TargetList = {age, sex, height};
new_col = dt << New Column("R1", Numeric, Continuous, Formula(
If(Row() == Col Min(Row(), :age, :sex), :age, .)
));
dt << Run Formulas;
new_col << Delete Formula;回覆:選擇重複的行條目,儲存其索引,然後建立一個不包含重複行的新清單。您可以使用表達式建立公式
Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
sel_cols = {"age", "sex", "height"};
colmin_expr = Expr(Col Min(Row()));
For Each({sel_col}, sel_cols,
Insert Into(colmin_expr, Name Expr(AsColumn(dt, sel_col)))
);
Eval(Substitute(
Expr(new_col = dt << New Column("R1", Numeric, Continuous, Formula(
If(Row() == _colminformula_, :age, .)
))),
Expr(_colminformula_), Name Expr(colmin_expr)
));
dt << Run Formulas;
new_col << Delete Formula;
您還應該能夠相當輕鬆地修改摘要版本以使用清單中的輸入