Skip to content
Prev 392275 / 398502 Next

Extract time and state of charge (Start and End) and Count

Thank you so much Avi, Rui and Jim...really appreciate your help.
I am so sorry for not able to make it clearly.

This is the expected output:
  Hour  Starting_SoC_of_12     Ending_SoC_of_12 frequency
   0      0                                    12
    603
   1      1                                    12
    136

dt <- dt3[which(dt3$Year==2014),]
head(dt); tail(dt)
dput(dt[1:5000,])

cols <- c("BatteryChargeStartDate", "BatteryChargeStopDate")
dt[cols] <- lapply(dt[cols], \(x) sub("\n", " ", x))

# use package lubridate to coerce to a datetime class
dt[cols] <- lapply(dt[cols], lubridate::dmy_hm)

h <- lubridate::hour(dt[["BatteryChargeStartDate"]])
aggregate(Starting_SoC_of_12 ~ h, dt, length)

Expected output:
  Hour  Starting_SoC_of_12 Ending_SoC_of_12 frequency
   0      0                     12             603
   1      1                     12             136




On Mon, Jul 18, 2022 at 12:04 PM roslinazairimah zakaria <
roslinaump at gmail.com> wrote: