a <- statuses[ID %between% c(59098, 59102), -c('Date')]
b <- restrictions[ID %between% c(59098, 59102), -c('Class', 'Date')]
c <- merge(a, b, by=c('Period', 'ID', 'MedID'), all.x=TRUE, allow.cartesian = TRUE)
d <- merge(statuses[ID %between% c(59098, 59102), -c('Date')],
restrictions[ID %between% c(59098, 59102), -c('Class', 'Date')],
by=c('Period', 'ID', 'MedID'), all.X=TRUE, allow.cartesian = TRUE)
a has 4 rows and b 5. c has 7 rows (correct) but d has only 5.
Given that c and d are basically doing the same merge, shouldn't they have the same number of rows?