I have two data frames, one wide and one long:
long_df = structure(list(PID = c(1001, 1001, 1001, 1002, 1002, 1002, 1002,
1003), scan_name = c("01_001A", "01_001B", "01_001C", "01_002A",
"01_002B", "01_002D", "01_002E", "01_003B")), row.names = c(NA,
-8L), class = c("tbl_df", "tbl", "data.frame"))
wide_df = structure(list(PID = c(1001, 1002, 1003), scan_name_1 = c("01_001A",
"01_002A", NA), scan_date_1 = structure(c(1206748800, 1240876800,
NA), class = c("POSIXct", "POSIXt"), tzone = "UTC"), scan_name_2 = c("01_001B",
"01_002B", "01_003B"), scan_date_2 = structure(c(1238544000,
1272672000, 1424736000), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
scan_name_3 = c("01_001C", NA, NA), scan_date_3 = structure(c(1301702400,
NA, NA), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
scan_name_4 = c(NA, "01_002D", NA), scan_date_4 = structure(c(NA,
1400112000, NA), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
scan_name_5 = c(NA, "01_002E", NA), scan_date_5 = structure(c(NA,
1430438400, NA), class = c("POSIXct", "POSIXt"), tzone = "UTC")), row.names = c(NA,
-3L), class = c("tbl_df", "tbl", "data.frame"))
I'm trying to get the values "scan_date_1", "scan_date_2", etc, from wide_df into the long_df.
The output I'm trying to get to looks like this:
goal_df = structure(list(PID = c(1001, 1001, 1001, 1002, 1002, 1002, 1002,
1003), scan_name = c("01_001A", "01_001B", "01_001C", "01_002A",
"01_002B", "01_002D", "01_002E", "01_003B"), scan_date = structure(c(1206748800,
1238544000, 1301702400, 1240876800, 1272672000, 1400112000, 1430438400,
1424736000), class = c("POSIXct", "POSIXt"), tzone = "UTC")), row.names = c(NA,
-8L), class = c("tbl_df", "tbl", "data.frame"))
Seems simple, but none of my attempts using merge/melt/etc, have been able to get there. Any and all help is much appreciated! (First time using "dput", so hopefully this is a replicable example)