Hi @nchan08,
Credit to @williaml and @nirgrahamuk for getting you to post some reproducible data.
The data is in the "wrong" format for R - it needs to be in the columns of a dataframe so that the required calculations can easily be made.
From your description, I think that you want to calculate lagged differences from each of the b and d columns, identify any rows where the differences are > 10%, and then filter the rows.
Try this code:
library(tidyverse)
library(lubridate)
# Edit some of the data to make bigger differences
b <- c(10.35,9.0,10.44,12.0,10.57,10.46,10.79,11.28,11.19,11.19,
11.33,11.08,11.17,10.84,10.50,10.53,10.46,10.83)
d <- c(10.21,10.45,10.30,10.34,10.63,12.0,9.0,10.89,11.00,
11.16,11.05,11.09,11.25,10.63,10.43,10.45,10.54,10.81)
ee <- c("06:00","06:30","07:00","07:30","08:00","08:30",
"09:00","09:30","10:00","10:30","11:00","11:30",
"12:00","12:30","13:00","13:30","14:00","14:30")
tt <- as_datetime(paste(today(), ee, ":00"))
DF <- data.frame(tt=tt, b=b, d=d)
# Calculate lagged differences in columns b and d
# Record if they are > +- 10%
DF %>%
mutate(lagb = lag(b),
lagd = lag(d),
b_diff = (b-lagb)/b,
d_diff = (d-lagd)/d,
b_omit = if_else(abs(b_diff) > 0.1, "Bad", "Good"),
d_omit = if_else(abs(d_diff) > 0.1, "Bad", "Good")) -> out_df
out_df
out_df %>%
filter(b_omit == "Good") %>%
filter(d_omit == "Good")
HTH