有人能帮忙吗?我有一个数据框(set_rise
),每行包含当天日落时间和第二天日出时间。我有第二个数据框(data
),其中有一个日期/时间列。我想在data
中创建第二列,该列包含与白天或黑夜对应的字母,方法是获取data
中的日期/时间,并检查它是否介于set_rise
中的任何时间之间。
#df1- sunset, sunrise times
set_rise
set rise
1 2013-03-01 18:28:00 2013-03-02 08:27:00
2 2013-03-02 18:31:00 2013-03-03 08:23:00
3 2013-03-03 18:35:00 2013-03-04 08:19:00
4 2013-03-04 18:38:00 2013-03-05 08:15:00
5 2013-03-05 18:42:00 2013-03-06 08:12:00
6 2013-03-06 18:45:00 2013-03-07 08:08:00
#df2 my data
timedate
1 2013-03-01 19:00:00
2 2013-03-03 10:00:00
3 2013-03-06 00:01:00
我希望得到这样的输出
data
timedate night_day
2013-03-01 19:00:00 N
2013-03-03 10:00:00 D
2013-03-06 00:01:00 N
Output dput(set_rise)
dput(set_rise)
structure(list(set = structure(list(sec = 0, min = 28L, hour = 18L,
mday = 1L, mon = 2L, year = 113L, wday = 5L, yday = 59L,
isdst = 0L, zone = "WET", gmtoff = NA_integer_), .Names = c("sec",
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst",
"zone", "gmtoff"), class = c("POSIXlt", "POSIXt")), rise = structure(list(
sec = 0, min = 27L, hour = 8L, mday = 2L, mon = 2L, year = 113L,
wday = 6L, yday = 60L, isdst = 0L, zone = "WET", gmtoff = NA_integer_), .Names = c("sec",
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst",
"zone", "gmtoff"), class = c("POSIXlt", "POSIXt")), night = "N"), .Names = c("set",
"rise", "night"), row.names = 1L, class = "data.frame")
dput(data)的输出结果
dput(data)
structure(list(timedate = structure(c(1362873600, 1362960000,
1364342400), class = c("POSIXct", "POSIXt"))), .Names = "timedate", row.names = c(NA,
-3L), class = "data.frame")
set_rise
,我得到了13-03-01
的日期(它是 13 年而不是 2013 年)!只需提供set_rise
和data
,跳过如何构建它们的步骤。完成后,请发布dput(set_rise)
和dput(data)
的输出。但在此之前,请检查日期是否符合您的意图。 - nicola