0
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?

Uwe
  • 41,420
  • 11
  • 90
  • 134
  • 3
    You're going to need to provide reproducible data that shows the problem. Otherwise we're all guessing. See https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – thelatemail Sep 02 '21 at 23:53
  • 1
    Also, you have a typo - `all.X=TRUE` instead of `all.x=TRUE` – thelatemail Sep 02 '21 at 23:54
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Sep 03 '21 at 00:49

1 Answers1

1

all.X=TRUE is wrong so it's not taking all from that side Change it to

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

Explains why d has same rows as B.

Miguel Suazo
  • 331
  • 1
  • 4