r - Classify date/time by tidal states -
i want classify df1 date/time tidal states given in df2. thing df2 gives exact times when tide @ heighest high or low.
i want change classifies tidal height based on being within 3-hour interval either side of high , low tide.
df1 <- data.frame(date_time = as.posixct(c("2015-09-06 09:00:00 bst", "2015-09-06 09:48:00 bst", "2015-09-06 10:37:00 bst", "2015-09-06 12:00:00 bst", "2015-09-06 12:48:00 bst","2015-09-06 13:35:00 bst"))) > df1 date_time 1 2015-09-06 09:00:00 2 2015-09-06 09:48:00 3 2015-09-06 10:37:00 4 2015-09-06 12:00:00 5 2015-09-06 12:48:00 6 2015-09-06 13:35:00 df2 <- data.frame(date_time = as.posixct(c("2015-09-06 07:09:00 gmt", "2015-09-06 13:18:00 gmt", "2015-09-06 19:52:00 gmt", "2015-09-07 02:01:00 gmt", "2015-09-07 08:28:00 gmt", "2015-09-07 14:43:00 gmt")), tide_state = c("low", "high", "low", "high", "low", "high")) df2 date_time tide_state 1 2015-09-06 07:09:00 low 2 2015-09-06 13:18:00 high 3 2015-09-06 19:52:00 low 4 2015-09-07 02:01:00 high 5 2015-09-07 08:28:00 low 6 2015-09-07 14:43:00 high i've tried using findinterval():
df1$tides <- df2$tide_state[findinterval(x = df1$date_time, vec = df2$date_time)] result:
df1 date_time tides 1 2015-09-06 09:00:00 low 2 2015-09-06 09:48:00 low 3 2015-09-06 10:37:00 low 4 2015-09-06 12:00:00 low 5 2015-09-06 12:48:00 low 6 2015-09-06 13:35:00 high desired result: (based on tide being 3-hours either side of high , low.
df1 date_time tides 1 2015-09-06 09:00:00 low 2 2015-09-06 09:48:00 low 3 2015-09-06 10:37:00 high 4 2015-09-06 12:00:00 high 5 2015-09-06 12:48:00 high 6 2015-09-06 13:35:00 high any appreciated
Comments
Post a Comment