2016-04-30 30 views
0

我想查找給定日期時間值(在數據幀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 

例如,輸入 「2016年1月27日14:00:00」 應該輸出:

索引2137,日期時間2016年1月27日14:00:00,關閉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

'數據[$日期時間== 「2016年1月27日14:00:00」,]' – Sotos

+0

非常感謝,不得不簡單。乾杯。 – Krug

回答

0

感謝@Sotos的答案:

DATA[DATA$DateTime == "2016-01-27 14:00:00",] 
相關問題