Lassen Sie mich sagen, was ich glaube, dass Sie fragen.
Sie möchten wissen, wie 2 Datumsspalten in einem Bereich von plus oder minus X Stunden abgeglichen werden.
Ist das richtig?
Befinden sich die Spalten in derselben Datentabelle oder möchten Sie über Datentabellen hinweg übereinstimmen, damit die Daten zusammengeführt werden können?
Wenn mehr als eine Zeile im Bereich von +/- Stunden gefunden wird, möchten Sie den nächstgelegenen Wert auswählen? Was ist, wenn es ein Unentschieden gibt?
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>
rote Fahnen in der Nähe von Nachbarn in einem Abstand von mehr als 2 Stunden
Der Aufruf [1] [1] in den knernsten Zeilen ruft das erste Element aus der zurückgegebenen Liste ab, bei der es sich um eine Matrix aus einem Element handelt, und ruft dann dieses Element als Skalarwert ab. Es ist die Zeilennummer.
Diese Technik funktioniert nicht, wenn Sie ein asymmetrisches Fenster benötigen (z. B. muss die B-Zeit innerhalb von 2 Stunden liegen nach Eine Zeit). Sie können es anpassen, indem Sie alle Zeilen innerhalb von 2 Stunden abrufen und dann die erste auswählen, die funktioniert.