Removing data points outside of working hours (based on time stamps)

47 Views Asked by At

So every second I have a sensor that makes a data point unless it is charging, so I can have up to 86400 data points a day, is it possible to remove the data points outside of a certain time range (7am-5pm) and weekends as well?

Here is what I've been using so far and the error that comes up

data1 <- readr::read_csv("AE1_07 DBG (2022-03-17)1sec.csv")
data1$Date <- as.Date(data1$timestamp)
data1$Time <- format(as.POSIXct(data1$timestamp), format = "%H:%M:%S")
colnames(data1)<- c('timestamp','Axis1', 'Axis2','Axis3','VM','Standing','Stepping','Sitting','Date','Time')
data1 <- mutate(data1, Cycling=case_when(VM > 40 ~ 1, VM <= 40 ~ 0))
data1 <- mutate(data1, New_Sitting= ifelse(Sitting==1 & Cycling==1, 0, ifelse(Sitting==1 & Cycling==0, 1,0)))
data1 <- subset (data1, select = -c(timestamp,Sitting))
col_order <- c("Date", "Time", "Axis1", "Axis2", "Axis3", "VM", "Standing", "Stepping","Cycling","New_Sitting" )
data1 <- data1[, col_order]
data1 %>% group_by(Date) %>% mutate_if(is.character,as.numeric) %>% summarise(across(Axis1:New_Sitting,sum))
data1$date <- paste(data1$Date, data1$Time)
data1 <- subset (data1, select = -c(Date, Time))
col_order <- c("date", "Axis1", "Axis2", "Axis3", "VM", "Standing", "Stepping","Cycling","New_Sitting" )
data1 <- data1[, col_order]
data2 <- selectByDate(data1,year = 2022, day="weekday", hour= 7:19)
Error in format.default(date, "%A") : invalid 'trim' argument

Here is the head of my data

# A tibble: 6 × 9
  date       Axis1 Axis2 Axis3    VM Standing Stepping Cycling
  <chr>      <dbl> <dbl> <dbl> <dbl>    <dbl>    <dbl>   <dbl>
1 2022-03-1…     0     0     0     0        0        0       0
2 2022-03-1…     0     0     0     0        0        0       0
3 2022-03-1…     0     0     0     0        0        0       0
4 2022-03-1…     0     0     0     0        0        0       0
5 2022-03-1…     0     0     0     0        0        0       0
6 2022-03-1…     0     0     0     0        0        0       0
# … with 1 more variable: New_Sitting <dbl>
0

There are 0 best solutions below