2017-10-02 15 views
-1

日に応じて時間を増やし、その時間をデータフレームに入れたいと考えています。私は月の日数に応じて時間を増やす

10/09/2017 3h00 
10/09/2017 5h00 
11/09/2017 6h00 
11/09/2017 8h00 
12/09/2017 9h00 

を持って初めにexampeについては

それから私、私が持っていると思います後:

10/09/2017 3h00 
10/09/2017 5h00 
11/09/2017 6h00 + 24h =28h 
11/09/2017 8h00 + 24h =32h 
12/09/2017 9h00 + 48h =57h 
13/09/2017 15h00 + 72h= 87h 

、ここで月/ 09/2017

ための同じ繰り返し私が探しているものです

2016-08-19 23h ... 2016-08-20 47h .... 2016-08-20 6

> dput(daily_data2) 
structure(list(visitorID = c("16081918503913361", "16081918503913361", 
"16081918503913361", "16081918503913361", "16081920380127901", 
"16081920380127901", "16081920380127901", "16081920380127901", 
"16081920380127901", "16081920380127901", "16081920380127901", 
"16081920380127901", "16081921092401601", "16081921092401601", 
"16081921092401601", "16081921092401601", "16081921092401601", 
"16081921092401601", "16041014505621221", "16041014505621221", 
"16041014505621221", "16041014505621221", "16081523021881101", 
"16081523021881101", "16081523021881101", "16081523021881101", 
"16082009423468441", "16082009423468441", "16082009423468441", 
"16082009423468441"), variationID = c(190949L, 190949L, 190949L, 
190949L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 190949L, 190949L, 190949L, 190949L, 190949L, 190949L, 190949L, 
190949L, 0L, 0L, 0L, 0L), categoryID = c(279L, 280L, 281L, 282L, 
279L, 280L, 281L, 282L, 279L, 280L, 281L, 282L, 279L, 280L, 279L, 
280L, 281L, 282L, 279L, 280L, 281L, 282L, 279L, 280L, 281L, 282L, 
279L, 280L, 281L, 282L), actionID = c(148156L, 148157L, 152184L, 
221911L, 838346L, 838347L, 116586L, 121437L, 214544L, 214545L, 
115960L, 123037L, 149591L, 149592L, 337193L, 337194L, 115960L, 
116590L, 125550L, 125551L, 115960L, 121891L, 185973L, 0L, 115960L, 
136482L, 875336L, 875337L, 115960L, 125404L), time = c("2016-08-19 17:45:19", 
"2016-08-19 17:45:19", "2016-08-19 17:45:19", "2016-08-19 17:45:19", 
"2016-08-19 18:59:19", "2016-08-19 18:59:19", "2016-08-19 18:59:19", 
"2016-08-19 18:59:19", "2016-08-19 18:59:19", "2016-08-19 18:59:19", 
"2016-08-19 18:59:19", "2016-08-19 18:59:19", "2016-08-19 19:27:07", 
"2016-08-19 19:27:07", "2016-08-19 19:27:07", "2016-08-19 19:27:07", 
"2016-08-19 19:27:07", "2016-08-19 19:27:07", "2016-08-19 23:33:46", 
"2016-08-19 23:33:46", "2016-08-19 23:33:46", "2016-08-19 23:33:46", 
"2016-08-20 07:13:32", "2016-08-20 07:13:32", "2016-08-20 07:13:32", 
"2016-08-20 07:13:32", "2016-08-20 08:52:12", "2016-08-20 08:52:12", 
"2016-08-20 08:52:12", "2016-08-20 08:52:12")), .Names = c("visitorID", 
"variationID", "categoryID", "actionID", "time"), row.names = c(NA, 
30L), class = "data.frame") 
> 
+2

'6H + 24時間= 30h' –

+2

の時間に差が出る:5Hここに は私の時間のフォーマットでありますどのような出力をしたいですか? '11/09/2017 8h00 + 24h = 32h'という文字列が本当に必要ですか? – PoGibas

+0

だから基本的に24 *(分(日)以来の日数)を各時間に追加したいのですか? – pyll

答えて

0

まず、我々はstart_dateを計算し、各日付:

start_date <- min(as.POSIXct(strptime(as.character(df$time),"%Y-%m-%d"))) 
df$hour <- paste0(round(difftime(df$time, start_date, units="hours"), 0),"h") 
df 


      visitorID variationID categoryID actionID    time hour 
1 16081918503913361  190949  279 148156 2016-08-19 17:45:19 18h 
2 16081918503913361  190949  280 148157 2016-08-19 17:45:19 18h 
3 16081918503913361  190949  281 152184 2016-08-19 17:45:19 18h 
4 16081918503913361  190949  282 221911 2016-08-19 17:45:19 18h 
5 16081920380127901   0  279 838346 2016-08-19 18:59:19 19h 
6 16081920380127901   0  280 838347 2016-08-19 18:59:19 19h 
7 16081920380127901   0  281 116586 2016-08-19 18:59:19 19h 
8 16081920380127901   0  282 121437 2016-08-19 18:59:19 19h 
9 16081920380127901   0  279 214544 2016-08-19 18:59:19 19h 
10 16081920380127901   0  280 214545 2016-08-19 18:59:19 19h 
11 16081920380127901   0  281 115960 2016-08-19 18:59:19 19h 
12 16081920380127901   0  282 123037 2016-08-19 18:59:19 19h 
13 16081921092401601   0  279 149591 2016-08-19 19:27:07 19h 
14 16081921092401601   0  280 149592 2016-08-19 19:27:07 19h 
15 16081921092401601   0  279 337193 2016-08-19 19:27:07 19h 
16 16081921092401601   0  280 337194 2016-08-19 19:27:07 19h 
17 16081921092401601   0  281 115960 2016-08-19 19:27:07 19h 
18 16081921092401601   0  282 116590 2016-08-19 19:27:07 19h 
19 16041014505621221  190949  279 125550 2016-08-19 23:33:46 24h 
20 16041014505621221  190949  280 125551 2016-08-19 23:33:46 24h 
21 16041014505621221  190949  281 115960 2016-08-19 23:33:46 24h 
22 16041014505621221  190949  282 121891 2016-08-19 23:33:46 24h 
23 16081523021881101  190949  279 185973 2016-08-20 07:13:32 31h 
24 16081523021881101  190949  280  0 2016-08-20 07:13:32 31h 
25 16081523021881101  190949  281 115960 2016-08-20 07:13:32 31h 
26 16081523021881101  190949  282 136482 2016-08-20 07:13:32 31h 
27 16082009423468441   0  279 875336 2016-08-20 08:52:12 33h 
28 16082009423468441   0  280 875337 2016-08-20 08:52:12 33h 
29 16082009423468441   0  281 115960 2016-08-20 08:52:12 33h 
30 16082009423468441   0  282 125404 2016-08-20 08:52:12 33h 
+0

それは非常にうまくいっている –

0
date_entry <- strptime(c("2017-09-10 03:45:19", 
       "2017-09-10 05:45:19", 
       "2017-09-11 06:45:19", 
       "2017-09-11 08:45:19", 
       "2017-09-12 09:45:19", 
       "2017-09-13 15:45:19"), "%Y-%m-%d %H:%M:%S") 

df <- data.frame(date_entry) 

df$start <- format(min(df$date_entry), "%Y-%m-%d") 

df$hour_entry <- hour(date_entry) 

# df$date <- format(df$date_entry, "%Y-%m-%d") 

df$date_diff <- as.Date(as.character(df$date_entry), format="%Y-%m-%d")- 
    as.Date(as.character(df$start), format="%Y-%m-%d") 

df$hour_diff <- paste0(as.character(df$hour_entry + 24*df$date_diff), "h") 
関連する問題