Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

時刻を5分間隔でまるめる

Last updated at Posted at 2014-06-27

時刻データをいろいろな間隔でまるめる(四捨五入)

round()関数で1時間毎にまるめる時は,"hours"と指定する

05:17","2014-06-30 13:45:17","2014-06-30 14:18:17"),
                      format = "%Y-%m-%d %H:%M:%S",tz="")
print(time.x1)
round(time.x1,"hours")
05:17 JST" "2014-06-30 13:45:17 JST" "2014-06-30 14:18:17 JST"
[1] "2014-06-30 14:00:00 JST" "2014-06-30 14:00:00 JST" "2014-06-30 14:00:00 JST"

14:00:00にまるめられるのは,13:30:00から14:29:59まで

1分毎は,"mins"で指定する
round(time.x1,"mins")

半端な間隔でまるめたいときは,xtsパッケージのalign.time()を使う。
指定した時間間隔(秒)で切り上げるので,予めまるめたい時間間隔の半分の時間を引いておくと良い。

5分毎にまるめる ```align.time(time.x1 - 560/2, 560)

30分毎にまるめる  ```align.time(time.x1 - 30*60/2, 30*60)

2時間毎にまるめる align.time(time.x1 - 2*60*60/2, 2*60*60)

plyr()が1.8.1にアップデートされてからround_any()関数が何故かおかしくなったのでメモ。round_any(time.x1, 5*60)で動いていたはず...

12
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up

Qiita Advent Calendar is held!

Qiita Advent Calendar is an article posting event where you post articles by filling a calendar 🎅

Some calendars come with gifts and some gifts are drawn from all calendars 👀

Please tie the article to your calendar and let's enjoy Christmas together!

12
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?