View source: R/merge_diftime.R
merge_diftime | R Documentation |
Functions that merges two dataframes that have measurements at different ages. It matches the closest measurement in data2 before, after, or before or after the measurement in data1. If a threshold is specified, it will ensure the closest measurement falls within that threshold or it will set it to missing.
merge_diftime(
data1,
data2,
id,
age,
threshold = Inf,
vars = NULL,
where = "both",
suffixes = c(".1", ".2"),
clean_vars = TRUE
)
data1 |
a dataframe that has the ids and ages of measurement that will serve as a reference for matching with data2 |
data2 |
a dataframe that has the ids and ages of measurement we would like to match with the reference id's and dates and data1 |
id |
either a character string, or a character vector of length 2. If the id variable in data1 and data2 have the same name, id is a character string. If the id variable of data1 and data2 are different, then id is a character vector, with the first value being the id variable of data1 and the second being the id variable for data2. |
age |
either a character string, or a character vector of length 2. If the age variable in data1 and data2 have the same name, age is a character string. If the age variable of data1 and data2 are different, then age is a character vector, with the first value being the age variable of data1 and the second being the age variable for data2. |
threshold |
a numeric value that provides the difference in time between measurements allowed. The numeric should be in the same units of age. |
vars |
optional character vector that provides the variable names for which this should be applied over. If specified, for each variable specified by var, only non-missing values will be considered when merging with the closest measurement date. |
where |
a character string that specifies where to look for the closest observation in data2 relative to data1. "before" means that merge_diftime will look before the reference observation in data1. "after" means the same except after. "both" means that merge_ditime will match using observations on either side of the reference observation in data1. |
suffixes |
specifies the suffix for non-unique variables between the two dataframes. However, even if the age and id variables are unique between the two dataframes, they will be assigned a suffix. |
clean_vars |
default is true. Will return all data1 columns and remove any duplicate columns from data2 with the exception of the age column. |
a dataframe where each unique subject and age measurement in data1 is matched with the closest aged measurement for that subject in data2.
William Mueller, Jorge Martinez Romero
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.