date_match | R Documentation |
match dates in a data frame by one-to-many merge and rank. Useful to match behavioral to brain over multiple timepoints.
date_match(
d1,
d2,
idcol,
datecol1,
datecol2 = datecol1,
all.x = F,
suffix.y = ".y",
maxdatediff = 180,
maxrank = 2 - 0.001
)
d1 |
– main dataframe (has the "true" date. one part of one-to-many) |
d2 |
– supplimental dataframe with dates to match (many part of one-to-many) |
datecol1 |
– date column one, this will be the id column |
all.x |
– weather or not to keep NAs (b/c match is over maxdatediff or does not existed) |
suffix.y |
– what to call the d2 columns that match d1 names |
maxdatediff |
– maximum time between matches (default 180 days) |
maxrank |
– highest index value of datediff ranked. set to 1 to ingore ties (deafult is 1.999) |
id |
– column in both d1 and d2 (lunaid) |
datecal2 |
– date column two. this will be the many in one-to-many merge. defaults to same name as datacol1 |
dummy1 <- data.frame(id=c(1,2,3,3),d=c(20120302,20120302,20120302,20150302),j=1)
dummy2 <- data.frame(id=c(1,2,3,3,3),d=c(20120202,20120402,20120902,20130902,20150102),j2=2)
dummy1$d <- lubridate::ymd(dummy1$d)
dummy2$d <- lubridate::ymd(dummy2$d)
date_match(dummy1,dummy2,'id','d')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.