JMP 社群您好,
我有兩個不同的資料表,它們共用一列,即批號(簡稱批號)。 (在 W10 上運行 JMP Pro 14.1.0)
資料表來自兩個不同的來源,其中的行數不同。 我想使用其中一個數據表來選擇另一個數據表中的匹配行。 批次中的值是連續/數字。 dt1 有 1430 行,dt2 有 158 行。 dt1 中的批次比 dt2 中的批次多,因此我需要使用 dt2 來僅選擇 dt1 中的匹配批次。
我以為我可以做一個簡單的: dt1<
我想我可以使用兩個for 循環來做到這一點,其中對於dt1 中的每一行,它將循環遍歷dt2 以查看它們在哪裡相等,不幸的是,這會導致225940 次比較,我認為這很很容易,但JMP 花費的時間要長得多比我想像的要好。
這是我寫的選擇程式碼:
For(l=1, l<=NRows(dt1), l++,
For(i=1, 1<=NRows(dt2), i++,
dt1<<SELECT where=""></SELECT>但這不起作用。 它似乎陷入了無限循環(不得不強制退出JMP)。
我在寫這篇文章時做了一些閱讀,因為我需要保留所有先前選擇的行,所以我需要呼叫當前選擇(“擴展”)選項。 所以,我肯定知道上面的程式碼不會工作,但它應該做一些事情。
一定有比 For 迴圈更快、更優雅的方法。
非常感謝任何反饋。
謝謝!,
DS
這裡有兩種方法可以做到這一點。第一種方法使用您的方法,但是,對於大數據表來說,它會很慢
Names Default To Here( 1 );
// create sample data
dtMain = New Table( "Main",
Add Rows( 2 ),
New Column( "lot",
Character,
"Nominal",
Set Values( {"a", "b", "c", "d", "e", "a", "b", "c"} )
)
);
dtSmall = New Table( "Small",
Add Rows( 2 ),
New Column( "lot",
Character,
"Nominal",
Set Values( {"a", "e"} ),
Set Display Width( 49 )
)
);
Names Default To Here( 1 );
dtMain << clear select;
For( i = 1, i <= N Rows( dtSmall ), i++,
dtMain << select where(
dtMain:Lot == dtSmall:Lot[i],
current selection( "extend" )
)
);
第二個會更有效地工作
Names Default To Here( 1 );
// create sample data
dtMain = New Table( "Main",
Add Rows( 2 ),
New Column( "lot",
Character,
"Nominal",
Set Values( {"a", "b", "c", "d", "e", "a", "b", "c"} )
)
);
dtSmall = New Table( "Small",
Add Rows( 2 ),
New Column( "lot",
Character,
"Nominal",
Set Values( {"a", "e"} ),
Set Display Width( 49 )
)
);
// Create a new column as a Select indicator
dtSmall << New Column( "Select", set each value( 1 ) );
// Update the Main table with values from the Small table
dtMain << Update( With( dtSmall ), Match Columns( :lot = :lot ) );
// Select the matching columns
dtMain << select where( :select == 1 );
// get rid of select columns
dtMain << delete columns( "Select" );
dtSmall << delete columns( "Select" );