Description Usage Arguments Examples
This function allows you to join longitudinal data sets.
1 2 | outer_right(x, y, x_id_col, y_id_col, x_date_col, y_date_col,
y_intvl_less = 0, y_intvl_more = 0, keep_x_id = TRUE)
|
x |
X data frame. |
y |
Y data frame. |
x_id_col |
Name of column in X data frame with IDs. |
y_id_col |
Name of column in Y data frame with IDs. |
x_date_col |
Name of column in X data frame with dates. |
y_date_col |
Name of column in Y data frame with dates. |
y_intvl_less |
Number of days before Y date to fuzzy match to X date. Defaults to 0. |
y_intvl_more |
Number of days after Y date to fuzzy match to X date. Defaults to 0. |
keep_x_id |
Keep column in X data frame with IDs? Defaults to TRUE. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # Define basic data frames X and Y
X <- data.frame(
x_id = c(1L, 1L, 1L, 2L, 2L, 3L, 3L, 4L, 5L, 5L),
x_date = as.Date(c("2015-06-01", "2016-06-28", "2017-05-25", "2014-02-23",
"2015-03-09", "2016-08-02", "2016-12-13", "2018-03-28",
"2017-05-17", "2018-04-03")),
x_data = runif(10, min = 0, max = 10))
Y <- data.frame(
y_id = c(1L, 1L, 2L, 2L, 2L, 3L, 4L, 4L, 5L, 5L),
y_date = as.Date(c("2015-06-01", "2017-05-20", "2014-02-23", "2015-03-10",
"2015-03-11", "2016-08-02", "2018-04-01", "2017-03-22",
"2017-05-16", "2017-05-17")),
y_data = runif(10, min = -100, max = 0))
# Use default values where possible
outer_right(x = X, y = Y,
x_id = "x_id", y_id = "y_id",
x_date = "x_date", y_date = "y_date")
# Define fuzzy date matching intervals and remove `y_id` column
intvl_less <- 5
intvl_more <- 3
outer_right(x = X, y = Y,
x_id = "x_id", y_id = "y_id",
x_date = "x_date", y_date = "y_date",
y_intvl_less = intvl_less, y_intvl_more = intvl_more,
keep_x_id = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.