我有兩個要通過時間戳連接的表,但是,時間戳並沒有完全同時記錄。 因此,我希望加入彼此相隔 5 分鐘以內的任何時間戳。 如果時間戳在其他表中沒有匹配的時間戳,我仍然希望保留行數據。 在 JSL 中有一種簡單的方法可以做到這一點嗎?
您可以在每個數據表中創建一個公式列,將您的時間戳列四捨五入到最接近的 5 分鐘,然後將這些列用於連接。在 JMP 14 中,如果您右鍵單擊時間戳列的標題,然後選擇新建公式列 -> 轉換 -> 舍入...,您將看到一個對話框,其中提供向上舍入、向下舍入或舍入的選項到您想要的最接近的時間增量。如果您沒有 JMP 14,則四捨五入到最接近的 5 分鐘間隔的公式如下所示:
回合(:時間戳/ 300)* 300
(注意 300 是 5 分鐘中的秒數)。
Tables->JMP Query Builder(或 Tables->Join)對話框有保留不匹配項和創建匹配標誌列的選項。
希望這可以幫助。
沒有內置平台可以根據您的需求進行模糊匹配連接。但是,可以使用 JSL 來獲得您需要的東西。
這是編寫請求腳本的一種方法的粗略示例
Names Default To Here( 1 );
// Create sample data tables
dt1 = New Table( "Data Table 1",
Add Rows( 100 ),
New Column( "DateTime",
Numeric,
"Continuous",
Format( "m/d/y h:m", 19 ),
Input Format( "m/d/y h:m" ),
Formula( Today() + Row() * In Minutes( 5 ) ),
Set Selected
)
);
dt1 << run formulas;
dt1:DateTime << delete formula;
dt2 = dt1 << Subset(
Sampling Rate( 0.25 ),
Selected columns only( 0 ),
output table name( "Data Table 2" ),
link to original table( 0 )
);
Current Data Table( dt2 );
For Each Row( :DateTime = :DateTime + In Minutes( Random Uniform( -100, 100 ) ) );
dt2 << sort( by( :DateTime ), order( ascending ), replace table( 1 ) );
// Create a column in data table 1 for reference
dt1 << New Column( "RowNum", formula( Row() ) );
dt1:RowNum << delete formula;
// Create in data table 2 a column that will hold the row to join to
dt2 << New Column( "Match Row" );
// Loop through data table 2 and find the rows in the first table that match
For( i = 1, i <= N Rows( dt2 ), i++,
checkVal = dt2:DateTime[i];
theRows = dt1 << get rows where(
:Datetime > checkVal - In Minutes( 5 ) & :DateTime < checkVal + In Minutes( 5 )
);
If( N Rows( theRows ) > 0,
minList = {};
For( k = 1, k <= N Rows( theRows ), k++,
Insert Into( minList, Abs( dt1:DateTime[theRows[k]] - checkVal ) )
);
dt2:Match Row[i] = theRows[Loc( minList, Min( minList ) )];
,
dt2:Match Row[i] = 0
);
);
// Join the tables
dt3 = dt1 << Join(
With( dt2 ),
Merge Same Name Columns,
By Matching Columns( :RowNum = :Match Row ),
Drop multiples( 0, 0 ),
Include Nonmatches( 1, 1 ),
Preserve main table order( 1 ),
output table name("Final Table")
);