match_ts_nearest_by_key: Match timeseries by key and time

View source: R/utils.R

match_ts_nearest_by_keyR Documentation

Match timeseries by key and time

Description

For two dataframes, d1 and d2, this function finds the positions in the second dataframe which, for each key (e.g., factor level, individual) in the first dataframe, are nearest in time (i.e., nearest neighbour interpolation accounting for observations from different factor levels).

Usage

match_ts_nearest_by_key(d1, d2, key_col, time_col)

Arguments

d1

A dataframe which includes a column that defines factor levels and a column that defines timestamps. The names of these columns need to match those in d2.

d2

A dataframe which includes a column that defines factor levels and a column that defines timestamps. The names of these columns need to match those in d1.

key_col

A character that defines the column name in d1 and d2 that distinguishes factor levels.

time_col

A character that defines the column name in d1 and d2 that defines timestamps.

Details

If there are multiple matches, only the first is returned.

Value

For a dataframe comprising observations from a series of factor levels (e.g., individuals) collected through time, the function returns a vector of positions in a second dataframe which, for the appropriate factor level, are nearest in time.

Author(s)

Edward Lavender


edwardlavender/fvcom.tbx documentation built on Nov. 26, 2022, 10:28 p.m.