给定日期/时间戳,查找给定行的所有值

时间:2016-04-30 19:35:07

标签: r time-series rows elements

我想在给定DateTime值的情况下找到给定行的所有值(在dataframe DATA中)。

DATA <- structure(list(DateTime = structure(list(sec = c(0, 0, 0, 0,0, 0, 0, 0, 0), min = c(30L, 15L, 0L, 45L, 30L, 15L, 0L, 45L,30L), hour = c(15L, 15L, 15L, 14L, 14L, 14L, 14L, 13L, 13L),mday = c(27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L), mon = c(0L,0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), year = c(116L, 116L, 116L,116L, 116L, 116L, 116L, 116L, 116L), wday = c(3L, 3L, 3L,3L, 3L, 3L, 3L, 3L, 3L), yday = c(26L, 26L, 26L, 26L, 26L,26L, 26L, 26L, 26L), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L,0L, 0L), zone = c("EST", "EST", "EST", "EST", "EST", "EST","EST", "EST", "EST"), gmtoff = c(NA_integer_, NA_integer_,NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,NA_integer_, NA_integer_)), .Names = c("sec", "min", "hour","mday", "mon", "year", "wday", "yday", "isdst", "zone", "gmtoff"), class = c("POSIXlt", "POSIXt")), Close = c(1127.2, 1127.5,1126.9, 1128.3, 1125.4, 1122.7, 1122.8, 1117.3, 1116), FOMCBinary = c(0,0, 0, 0, 0, 0, 1, 0, 0)), .Names = c("DateTime", "Close", "FOMCBinary"), row.names = 2131:2139, class = "data.frame") 

#Output for DATA: 
                DateTime  Close FOMCBinary
2131 2016-01-27 15:30:00 1127.2          0
2132 2016-01-27 15:15:00 1127.5          0
2133 2016-01-27 15:00:00 1126.9          0
2134 2016-01-27 14:45:00 1128.3          0
2135 2016-01-27 14:30:00 1125.4          0
2136 2016-01-27 14:15:00 1122.7          0
2137 2016-01-27 14:00:00 1122.8          1
2138 2016-01-27 13:45:00 1117.3          0
2139 2016-01-27 13:30:00 1116.0          0

例如,输入&#34; 2016-01-27 14:00:00&#34;应输出:

Index 2137,DateTime 2016-01-27 14:00:00,Close 1122.8,FOMCBinary 1。

我怎么能这样做?我尝试了以下但没有成功:

DATA$DateTime["2016-01-27 14:00:00"]
DATA$DateTime[,DateTime = "2016-01-27 14:00:00"]
DATA$DateTime[DateTime = "2016-01-27 14:00:00"]

1 个答案:

答案 0 :(得分:0)

感谢@Sotos的回答:

DATA[DATA$DateTime == "2016-01-27 14:00:00",]
相关问题