Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

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

round()関数で1時間毎にまるめる時は,"hours"と指定する
time.x1 <- as.POSIXct(c("2014-06-30 14: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")

[1] "2014-06-30 14: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 - 5*60/2, 5*60)

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)で動いていたはず...

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away