I'm attempting to match dates in 3 variables (date1:date3) to my main date variable.
I've tried using dplyr join methods but to no avail, as when I specify the variables to merge by it will only combine them together instead of matching them across columns.
I've attached my reprex attempt and the ideal output, any help would be appreciated. Thanks.
#Example dataframe 1
patientid <- c("-2147483645", "-2147483645", "-2147483645", "-2147483645", "-2147483645")
date <- c("2018-08-30", "2018-09-04", "2018-09-13", "2018-09-28", "2018-10-11")
#Example dataframe 2 (one date variable for example as dates in others are too far down the dataframe)
patientid <- c("-2147483645", "-2147483645", "-2147483645", "-2147483645", "-2147483645")
date1 <- c("2018-09-04", "2018-09-28")
#Current output
patientid date date1
1 2018-08-30 2018-09-04
1 2018-09-04 NA
1 2018-09-13 2018-09-28
1 2018-09-28 NA
#Ideal output
patientid date date1 exacerbation
1 2018-08-30 NA NO
1 2018-09-04 2018-09-04 YES
1 2018-09-13 NA NO
1 2018-09-28 2018-09-28 YES
Sorry, I don't understand what you're trying to do, and the posted example doesn't clear it up for me. When you say "match" here, what do you mean? Perhaps you can post a more developed example?
So you're looking for a way to keep both sets of join keys in the output? This is currently only supported in nest_join() by way of the keep = TRUE argument. Once, you have both keys, creating the exacerbation variable is straightforward.
In dplyr 1.0.0, the keep parameter will be added to the outer joins after which this operation can be performed without have to resort to tidyr::unnest().