You can use findInterval
, assuming the first data frame is dateDf
and the second one is typeDf
:
dateDf$ReagentType <- typeDf$ReagentType[findInterval(dateDf$Date, typeDf$Date)]
Data:
dput(dateDf)
structure(list(Date = structure(c(16801, 16802, 16803, 16804,
16805, 16806, 16807, 16808, 16809, 16810, 16811, 16812, 16813,
16814, 16815, 16816, 16817, 16818, 16819, 16820, 16821, 16822,
16823, 16824, 16825, 16826, 16827, 16828, 16829, 16830, 16831,
16832, 16833, 16834, 16835, 16836, 16837, 16838, 16839, 16840,
16841, 16842, 16843, 16844, 16845, 16846, 16847, 16848, 16849,
16850, 16851, 16852, 16853, 16854, 16855, 16856, 16857, 16858,
16859, 16860, 16861), class = "Date"), ReagentType = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("A",
"B"), class = "factor")), .Names = c("Date", "ReagentType"), row.names = c(NA,
-61L), class = "data.frame")
dput(typeDf)
structure(list(Date = structure(c(16801, 16832, 16846, 16890), class = "Date"),
ReagentType = structure(c(1L, 2L, 1L, 2L), .Label = c("A",
"B"), class = "factor")), .Names = c("Date", "ReagentType"
), row.names = c(NA, -4L), class = "data.frame")