match_ts_nearest | R Documentation |
This function is like match
, but the aim is, for a given sequence of times (times
), to find the positions in another sequence of times (lookup
) that are nearest in time to those in the first sequence. In other words, for every time inputted, match_ts_nearest()
finds the position in another sequence of times which is nearest in time to that time. This is useful if, for example, you have an existing dataframe to which you want to add the observations, held in another dataframe, that are nearest in time to observations in the first dataframe (i.e., nearest neighbour interpolation). This function uses data.table
for fast matching, even with very large vectors.
match_ts_nearest(times, lookup)
times |
A vector of timestamps for which you want to identify the position of the nearest timestamp in another vector ( |
lookup |
A vector of timestamps for which you will determine the position of the nearest timestamp to each time in |
If there are multiple matches, only the first is returned.
For a sequence of times (times
), the function returns a vector of the positions of the nearest times in another sequence (lookup
).
Edward Lavender
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.