-1

I am trying to join two dataframe by date-time but I have not been successful. I have checked the seconds and they seem to have matches but an inner join return no results. I used merge and tidyverse with the same output. I am including a sample of my actual objects in the script below:

library(tidyverse)

a <- structure(
  list(
    date = structure(c(
      126230400, 126234000, 126237600,
      126241200, 126244800, 126248400, 126252000, 126255600, 126259200,
      126262800, 126266400, 126270000, 126273600, 126277200, 126280800,
      126284400, 126288000, 126291600, 126295200, 126298800, 126302400,
      126306000, 126309600, 126313200
    ), class = c("POSIXct", "POSIXt"), tzone = "UTC"), wd = c(
      303, 317, 309, 312, 274, 298, 311,
      298, 314, 303, 303, 302, 305, 303, 277, 281, 284, 276, 283, 289,
      262, 284, 281, 287
    ), ws = c(
      4.6, 5.2, 4.6, 4.1, 3.1, 4.1, 2.6,
      4.6, 6.2, 2.1, 3.1, 4.6, 4.1, 4.6, 4.6, 5.2, 4.1, 4.1, 4.1, 4.1,
      4.1, 4.6, 3.6, 3.6
    )
  ),
  row.names = c(NA, -24L), class = c(
    "tbl_df",
    "tbl", "data.frame"
  )
)

b <- structure(
  list(
    date = structure(c(
      126230400, 126234000, 126237600,
      126259200, 126262800, 126266400, 126270000, 126273600, 126277200
    ), class = c("POSIXct", "POSIXt"), tzone = "UTC"), wd = c(
      303,
      321, 292, 291, 309, 296, 282, 285, 288
    ), ws = c(
      3.6525524, 3.85833,
      4.6814404, 4.115552, 4.0126632, 3.4467748, 6.0189948, 5.7103284,
      4.9386624
    )
  ),
  row.names = c(NA, -9L), class = c(
    "tbl_df", "tbl",
    "data.frame"
  )
)

a %>% inner_join(b)
camille
  • 16,432
  • 18
  • 38
  • 60
rjss
  • 935
  • 10
  • 23

1 Answers1

1

I think that what your are using try to merge using all variables as keys. Try this:

c <- inner_join(a,b, by = "date")

Hope it help

FALL Gora
  • 481
  • 3
  • 8