inner: A Function to Perform Inner Joins of Longitudinal Data

Description Usage Arguments Examples

Description

This function allows you to join longitudinal data sets.

Usage

1
2
inner(x, y, x_id_col, y_id_col, x_date_col, y_date_col, x_intvl_less = 0,
  x_intvl_more = 0, keep_y_id = TRUE)

Arguments

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.

x_intvl_less

Number of days before X date to fuzzy match to Y date. Defaults to 0.

x_intvl_more

Number of days after X date to fuzzy match to Y date. Defaults to 0.

keep_y_id

Keep column in Y data frame with IDs? Defaults to TRUE.

Examples

 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
inner(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
inner(x = X, y = Y,
      x_id = "x_id", y_id = "y_id",
      x_date = "x_date", y_date = "y_date",
      x_intvl_less = intvl_less, x_intvl_more = intvl_more,
      keep_y_id = FALSE)

ldnicolasmay/FuzzyDateJoin documentation built on May 27, 2019, 3:31 p.m.