2016-07-23 4 views
0

私は、次のような二つの異なる日付の間でデータフレームを取得することができます。R - 2つの同じ日付間で行を取得しますか?

thisYear <- data[data$date >= "2016-07-18" & data$date <= "2016-07-19", ] 

結果:

18 rows // becos there are data on the 2016-07-18 

しかし、私は同じ日付を照会場合:

thisYear <- data[data$date >= "2016-07-18" & data$date <= "2016-07-18", ] 

結果:

0 row 

返信したい:

18 rows // becos there are data on the 2016-07-18 

可能でしょうか?どうしたらいいですか?

マイデータフレーム:

structure(list(particles = structure(c(1L, 3L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 6L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 4L, 4L, 
4L, 3L, 3L, 3L, 3L, 5L, 6L, 5L, 3L), .Label = c("1", "11", "1.1", 
"2", "2.1", "3.1"), class = "factor"), humidity = structure(c(4L, 
7L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 6L, 1L, 1L, 1L, 
5L, NA, NA, NA, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("0.1", 
"1", "1.1", "1.3", "21", "2.1", "3"), class = "factor"), timestamp = c(1468833354929, 
1468833365186, 1468833378458, 1468833538213, 1468833538416, 1468833538613, 
1468833538810, 1468833538986, 1468833539172, 1468833539358, 1468833539539, 
1468833554592, 1468833559059, 1468833562357, 1468833566225, 1468833573486, 
1468840019118, 1468840024950, 1469029568849, 1469029584243, 1469029590530, 
1469029622391, 1469029623598, 1469245154003, 1469245156533, 1469245156815, 
1469245157123, 1469245162358, 1469245165911, 1469245170178, 1469245173788 
), date = structure(c(1468833354.929, 1468833365.186, 1468833378.458, 
1468833538.213, 1468833538.416, 1468833538.613, 1468833538.81, 
1468833538.986, 1468833539.172, 1468833539.358, 1468833539.539, 
1468833554.592, 1468833559.059, 1468833562.357, 1468833566.225, 
1468833573.486, 1468840019.118, 1468840024.95, 1469029568.849, 
1469029584.243, 1469029590.53, 1469029622.391, 1469029623.598, 
1469245154.003, 1469245156.533, 1469245156.815, 1469245157.123, 
1469245162.358, 1469245165.911, 1469245170.178, 1469245173.788 
), class = c("POSIXct", "POSIXt"), tzone = "Asia/Singapore")), .Names = c("particles", 
"humidity", "timestamp", "date"), row.names = c(NA, -31L), class = "data.frame") 

答えて

1

あなたの構文に固執したい場合は、のようなas.Dateですべてを包むが:

data[as.Date(data$date) >= as.Date("2016-07-18") & as.Date(data$date) <= as.Date("2016-07-18"), ] 

    particles humidity timestamp    date 
1   1  1.3 1.468833e+12 2016-07-18 17:15:54 
2  1.1  3 1.468833e+12 2016-07-18 17:16:05 
3  2.1  1.1 1.468833e+12 2016-07-18 17:16:18 
4  2.1  1.1 1.468834e+12 2016-07-18 17:18:58 
5  2.1  1.1 1.468834e+12 2016-07-18 17:18:58 
6  2.1  1.1 1.468834e+12 2016-07-18 17:18:58 
7  2.1  1.1 1.468834e+12 2016-07-18 17:18:58 
8  2.1  1.1 1.468834e+12 2016-07-18 17:18:58 
9  2.1  1.1 1.468834e+12 2016-07-18 17:18:59 
10  2.1  1.1 1.468834e+12 2016-07-18 17:18:59 
11  2.1  1.1 1.468834e+12 2016-07-18 17:18:59 
12  3.1  1.1 1.468834e+12 2016-07-18 17:19:14 
13  11  1.1 1.468834e+12 2016-07-18 17:19:19 
14  11  2.1 1.468834e+12 2016-07-18 17:19:22 
15  11  0.1 1.468834e+12 2016-07-18 17:19:26 
16  1.1  0.1 1.468834e+12 2016-07-18 17:19:33 
17  1.1  0.1 1.468840e+12 2016-07-18 19:06:59 
18  1.1  21 1.468840e+12 2016-07-18 19:07:04 

私はどうなるのための:

library(dplyr) 
filter(data, as.Date(date) >= as.Date("2016-07-18") & as.Date(data$date) <= as.Date("2016-07-18")) 

    particles humidity timestamp    date 
1   1  1.3 1.468833e+12 2016-07-18 17:15:54 
2  1.1  3 1.468833e+12 2016-07-18 17:16:05 
3  2.1  1.1 1.468833e+12 2016-07-18 17:16:18 
4  2.1  1.1 1.468834e+12 2016-07-18 17:18:58 
5  2.1  1.1 1.468834e+12 2016-07-18 17:18:58 
6  2.1  1.1 1.468834e+12 2016-07-18 17:18:58 
7  2.1  1.1 1.468834e+12 2016-07-18 17:18:58 
8  2.1  1.1 1.468834e+12 2016-07-18 17:18:58 
9  2.1  1.1 1.468834e+12 2016-07-18 17:18:59 
10  2.1  1.1 1.468834e+12 2016-07-18 17:18:59 
11  2.1  1.1 1.468834e+12 2016-07-18 17:18:59 
12  3.1  1.1 1.468834e+12 2016-07-18 17:19:14 
13  11  1.1 1.468834e+12 2016-07-18 17:19:19 
14  11  2.1 1.468834e+12 2016-07-18 17:19:22 
15  11  0.1 1.468834e+12 2016-07-18 17:19:26 
16  1.1  0.1 1.468834e+12 2016-07-18 17:19:33 
17  1.1  0.1 1.468840e+12 2016-07-18 19:06:59 
18  1.1  21 1.468840e+12 2016-07-18 19:07:04 
+0

おかげで答え!できます! – laukok

関連する問題