根據常見變量列表進行更多連接你好,
我想替換此示例中的硬編碼列名稱:
dt = dt1 << Join(
With( dt_ref ),
Select(
:result_Rx_RSSI_,
:result_snr_Rx_RSSI_,
:type_,
:rat_,
:trx_,
),
SelectWith( :result_Rx_RSSI_ref, :result_snr_Rx_RSSI_ref, ),
By Matching Columns(
:type_ = :type_,
:rat_ = :rat_,
:trx_ = :trx_,
),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 ),
Output Table( "merged_results" )
);
用一些東西開頭
common_vars = {"type_", "rat_", "trx};
dt1_only_vars = {"result_Rx_RSSI_", "result_snr_Rx_RSSI_"};
dt_ref_only_vars = {"result_Rx_RSSI_ref", "result_snr_Rx_RSSI_ref"};... 這應該導致相同的結果。
我怎麼做?
謝謝您的幫助!
Re:根據常見變量列表進行更多連接謝謝!這比我的方法更容易閱讀。Re:根據常見變量列表進行更多連接也許我過分簡化了你的情況,但是,僅供參考,這也有效:
dt1 = NewTable("One",
NewColumn("A", Values([1,2])),
NewColumn("B", Values([3,4])),
NewColumn("K1", Values([5,6])),
NewColumn("K2", Values([7,8]))
);
dt2 = NewTable("Two",
NewColumn("C", Values([9,10])),
NewColumn("D", Values([11,12])),
NewColumn("K2", Values([5,6])),
NewColumn("K1", Values([7,8]))
);
dt1KeyCols = {"K1", "K2"};
dt2KeyCols = {"K2", "K1"};
dtFinal = dt1 << Join(
With(dt2),
By Matching Columns( dt1KeyCols = dt2KeyCols ),
Output Table( "Joined" )
);Re:根據常見變量列表進行更多連接感謝您的反饋。
這是我通過這篇博客文章解決它的方式:
http://www.pega-analytics.co.uk/blog/handling-lists-of-columns/
common_vars = {"type_", "rat_", "trx"};
dt1_only_vars = {"result_Rx_RSSI_", "result_snr_Rx_RSSI_"};
dt_ref_only_vars = {"result_Rx_RSSI_ref", "result_snr_Rx_RSSI_ref"};
col_names = dt1_only_vars || common_vars;
match_str = "";
For( i = 1, i <= N Items( common_vars ), i++,
match_col_name = common_vars[i];
mstr = Eval Insert( ":^match_col_name^ = :^match_col_name^," );
match_str = match_str || mstr;
);
// this is UGLY but I do not know any other way (yet?)
dt_str = Eval Insert(
"dt = dt1 << Join(
With( dt_ref ),
Select(
Eval( col_names )
),
SelectWith( Eval(dt_ref_only_vars) ),
By Matching Columns(
^match_str^
),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 ),
Output Table( \!"merged_results\!" ));"
);
Eval( Parse( dt_str ) );Re:根據常見變量列表進行更多連接嗨,亞歷克斯!
首先,感謝您使您的示例比原始問題更難打字!:)
我不清楚你為什麼要使用一個公共變量列表進行連接。 變量會改變嗎?用戶對話會有用嗎?你的理由可能會影響你應該採取的方向。
儘管如此,讓我們考慮有人必須在你的無分數數據集中維護“參考值”,並且記錄No Country數據集值沒有No Score值的情況會有所幫助...這將表明Left Outer Join將是適當。
dt_recombined = Query(
Table( dt_no_country, "t1" ),
Table( dt_no_score, "t2" ),
"SELECT t1.Name AS [Name from Table1], t1.Score, t1.[100m], t1.[Long Jump], t1.[Shot Put], t1.[High Jump], t1.[400m], t1.[100m hurdles], t1.Discus, t1.[Pole Vault], t1.Javelin, t1.[1500m],
t2.Name AS [Name from Table2], t2.Country
FROM t1
LEFT OUTER JOIN t2
ON ( t1.Name = t2.Name and
t1.[100m] = t2.[100m] and
t1.[Long Jump] = t2.[Long Jump] and
t1.[Shot Put] = t2.[Shot Put] and
t1.[High Jump] = t2.[High Jump] and
t1.[400m] = t2.[400m] and
t1.[100m hurdles] = t2.[100m hurdles] and
t1.Discus = t2.Discus and
t1.[Pole Vault] = t2.[Pole Vault] and
t1.Javelin = t2.Javelin and
t1.[1500m] = t2.[1500m] ) " ); 如果您確實需要,可以輕鬆地將變量轉換為可以隨意評估和替換的表達式。
Re:根據常見變量列表進行更多連接dt = Open( "$SAMPLE_DATA/Decathlon.jmp" );
dt_no_score = dt << Subset(
Output Table( "Decathlon_no_score" ),
All rows,
columns(
:Name,
:Country,
:Name( "100m" ),
:Long Jump,
:Shot Put,
:High Jump,
:Name( "400m" ),
:Name( "100m hurdles" ),
:Discus,
:Pole Vault,
:Javelin,
:Name( "1500m" )
)
);
dt_no_country = dt << Subset(
Output Table( "Decathlon_no_country" ),
All rows,
columns(
:Name,
:Score,
:Name( "100m" ),
:Long Jump,
:Shot Put,
:High Jump,
:Name( "400m" ),
:Name( "100m hurdles" ),
:Discus,
:Pole Vault,
:Javelin,
:Name( "1500m" )
)
);
dt_recombined = dt_no_country << Join(
With( dt_no_score ),
Select(
:Name,
:Score,
:Name( "100m" ),
:Long Jump,
:Shot Put,
:High Jump,
:Name( "400m" ),
:Name( "100m hurdles" ),
:Discus,
:Pole Vault,
:Javelin,
:Name( "1500m" )
),
SelectWith( :Country ),
By Matching Columns(
:Name = :Name,
:Name( "100m" ) = :Name( "100m" ),
:Long Jump = :Long Jump,
:Shot Put = :Shot Put,
:High Jump = :High Jump,
:Name( "400m" ) = :Name( "400m" ),
:Name( "100m hurdles" ) = :Name( "100m hurdles" ),
:Discus = :Discus,
:Pole Vault = :Pole Vault,
:Javelin = :Javelin,
:Name( "1500m" ) = :Name( "1500m" )
),
Drop multiples( 0, 0 ),
Include Nonmatches( 0, 0 ),
Preserve main table order( 1 )
)
Re:根據常見變量列表進行更多連接嗨,亞歷克斯!
有很多方法可以做到這一點。
你可以發布一些(匿名的,如果必要的話)dt1和dt_ref數據集嗎?