How to merge long datasets?

Hi, and thanks for helping me out!

I have two datasets of different lengths. One has about 1,500,000 observations, and the other has less than 500. I want to merge them.

In the example below, I want to add the variable event from dt2 to dt1, matching its value based on the same values for name and time.

name <- c("A", "A", "A", "A", "B", "B", "B", "B")
location <- c("x", "x", "y", "y", "w", "w", "z", "z")
time <- c(1, 2, 1, 2, 3, 4, 3, 4)
dt1 <- data.frame(name, location, time)
dt

  name location time
1    A        x    1
2    A        x    2
3    A        y    1
4    A        y    2
5    B        w    3
6    B        w    4
7    B        z    3
8    B        z    4

name <- c("A", "B")
time <- c(2, 4)
event <- c(TRUE, TRUE)
dt2 <- data.frame(name, time, event)
dt2

  name time event
1    A    2  TRUE
2    B    4  TRUE

In the end, the ideal solution would be something like this:

  name location time event
1    A        x    1  NA
2    A        x    2  TRUE
3    A        y    1  NA
4    A        y    2  TRUE
5    B        w    3  NA
6    B        w    4  TRUE
7    B        z    3  NA
8    B        z    4  TRUE

I have tried merge(dt1, dt2, all.x = all), but I get this error:

long vectors not supported yet: util.c:666

I believe this is due to the size of my longer dataset. Any suggestion on how to address this issue?

Thank you!

I think you just made a mistake setting all.x;
what would all resolve to ?
try

merge(dt1, dt2,
      all.x = TRUE)
2 Likes

Oops... you were right! Thanks a lot!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.