Consentitemi di affermare ciò che credo stiate chiedendo.
Vuoi sapere come abbinare 2 colonne di date in un intervallo di più o meno X numero di ore.
È corretto?
Le colonne si trovano nella stessa tabella di dati o stai cercando di abbinare tra le tabelle di dati, in modo che i dati possano essere uniti?
Se viene trovata più di una riga nell'intervallo +/- ore, si desidera scegliere il valore più vicino? E se c'è un pareggio?
dt = New Table( "Untitled 3",
Add Rows( 20 ),
New Column( "atime",
Numeric,
"Continuous",
Format( "ddMonyyyy h:m", 19 ),
Input Format( "ddMonyyyy h:m" ),
Formula( As Date( Random Uniform( Today() - 100000, Today() + 100000 ) ) ),
Set Display Width( 250 )
),
New Column( "closest b time",
Numeric,
"Continuous",
Format( "ddMonyyyy h:m", 19 ),
Input Format( "ddMonyyyy h:m" ),
Set Display Width( 250 )
),
New Column( "btime",
Numeric,
"Continuous",
Format( "ddMonyyyy h:m", 19 ),
Input Format( "ddMonyyyy h:m" ),
Formula( As Date( Random Uniform( Today() - 100000, Today() + 100000 ) ) ),
Set Display Width( 250 )
),
New Column( "closest a time",
Numeric,
"Continuous",
Format( "ddMonyyyy h:m", 19 ),
Input Format( "ddMonyyyy h:m" ),
Set Display Width( 250 )
)
);
dt << runformulas;
atime << deleteformula;
btime << deleteformula;
// here it is: find both backwards and forwards nearest neighbor
kdtA = KDTable( dt:atime << getvalues );
kdtB = KDTable( dt:btime << getvalues );
For( irow = 1, irow <= N Rows( dt ), irow += 1,
// look up the row of the nearest A time to this row's B time
closeA = (kdtA << knearestrows( 1, Matrix( dt:btime[irow] ) ))[1][1];
// get the actual A time from that row and keep it in this row.
dt:closest a time[irow] = dt:atime[closeA];
// flag times that are too far away
if(abs(dt:closest a time[irow]-btime[irow])>inhours(2),dt:closest a time<<COLOR cells="">inhours(2),dt:closest b time<<COLOR cells=""></COLOR></COLOR>
bandiere rosse vicino ai vicini nel tempo che sono distanti più di 2 ore
il [1] [1] nella chiamata alle righe più Knightest sta ottenendo il primo elemento dall'elenco restituito, che è una matrice di un elemento, quindi ottiene quell'elemento come valore scalare. È il numero di riga.
Questa tecnica non funzionerà se hai bisogno di una finestra asimmetrica (come il tempo B deve essere entro 2 ore dopo Un tempo). Puoi adattarlo ottenendo tutte le righe entro 2 ore, quindi selezionando il primo che funziona.