Tracy Pan
Tracy Pan

Reputation: 1

The function cut(xxx,"sec") doesn't cut time by second correctly

When I use cut(tmp$time,"sec") to proceed

       time lasting  elec
39 2013-04-18 13:06:25 8355222 -66.4
40 2013-04-18 13:06:25 8696122 -20.9
41 2013-04-18 13:06:27 9310817 -21.2
42 2013-04-18 13:06:25 9715650 -21.0
43 2013-04-18 13:06:26  338875 -29.6

The result shows

[1] 2013-04-18 13:06:25 2013-04-18 13:06:25 2013-04-18 13:06:27 2013-04-18 13:06:25
[5] 2013-04-18 13:06:25

But I think [5] should be 2013-04-18 13:06:26.What's the problem?

Upvotes: 0

Views: 887

Answers (1)

B Williams
B Williams

Reputation: 2050

This works fine, you may want to check your date format.

library(lubridate)
df <- data.frame(time = ymd_hms(c('2013-04-18 13:06:25',
                                  '2013-04-18 13:06:25',
                                  '2013-04-18 13:06:27',
                                  '2013-04-18 13:06:25',
                                  '2013-04-18 13:06:26' )))

cut(df$time, "sec")

[1] 2013-04-18 13:06:25 2013-04-18 13:06:25 2013-04-18 13:06:27 2013-04-18 13:06:25
[5] 2013-04-18 13:06:26
Levels: 2013-04-18 13:06:25 2013-04-18 13:06:26 2013-04-18 13:06:27

Upvotes: 1

Related Questions