Skip to content
Prev 392266 / 398502 Next

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

Rui,

The posted data was likely not well chosen as it has no rows that satisfy what I thought was the requirement of going from 0 to 12.

Questions here can often be written more clearly. We can all guess, but my guess was a bit like yours that he/she wanted to count how many rows there are per specific dates/hours (meaning up to 24 per day) that also satisfy a filter requirement. Of course, it is also possible that they do not care about what days, but want to know what happens any day between 9 and 10 Am and other possibilities.

It would be nice if people who asked questions followed up so we stop wasting our time answering what was not asked!



-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Rui Barradas
Sent: Monday, July 18, 2022 1:11 PM
To: roslinazairimah zakaria <roslinaump at gmail.com>; R help Mailing list <r-help at r-project.org>
Subject: Re: [R] Extract time and state of charge (Start and End) and Count

Hello,

I'm not sure I understand the problem. Do you want counts of how many rows are there per hour?


# these columns need to be fixed
cols <- c("BatteryChargeStartDate", "BatteryChargeStopDate")
dt_2014[cols] <- lapply(dt_2014[cols], \(x) sub("\n", " ", x))
# use package lubridate to coerce to a datetime class
dt_2014[cols] <- lapply(dt_2014[cols], lubridate::dmy_hm)

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



It would be better if you post the expected output corresponding to the 
posted data set.

Hope this helps,

Rui Barradas

?s 05:04 de 18/07/2022, roslinazairimah zakaria escreveu:
______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.