split or subset data into 30 minute intervals

冷暖自知 提交于 2019-11-29 02:38:12

Here's a one-liner for you (dat being your dataframe):

split(dat, cut(strptime(paste(dat$date, dat$time), format="%F %R"),"30 mins"))

Indeed cut.POSIXt accepts as break values

an interval specification, one of "sec", "min", "hour", "day", "DSTday", "week", "month", "quarter" or "year", optionally preceded by an integer and a space, or followed by "s".

Additionnaly, I used %F %R as a shortcut for %Y-%m-%d %H:%M: see ?strptime to see all possible formats.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!