Skip to content
Back to formatted view

Raw Message

Message-ID: <CA+8X3fWsD0ECXabR-kQYs+=UvxR5ax7UJQzcwGzvm55AMFhyYA@mail.gmail.com>
Date: 2022-07-20T00:49:00Z
From: Jim Lemon
Subject: Extract time and state of charge (Start and End) and Count
In-Reply-To: <CANTvJZ++YKuq+JsbiujeaRSfkPgkY33g_GuhhHHUUpST3CieLQ@mail.gmail.com>

Hi Roslina,
I think you have changed the code as "bc_start" in my code is
"BCStartTime" in yours. When I run the attached code, I get a data
frame "hourly_SoC" that looks right, and a matrix "result" (hour by
SoC) that checks against the data frame. I have tried to comment the
code so that you an see what I am doing.

Jim

On Wed, Jul 20, 2022 at 1:18 AM roslinazairimah zakaria
<roslinaump at gmail.com> wrote:
>
> Hi Jim,
>
> I tried to run your code and got this error.
>
> > # get the temporal order of observations
> > obs_order <- order(c(as.numeric(dt$BCStartTime),as.numeric(dt$BCStopTime)))
> Warning messages:
> 1: In order(c(as.numeric(dt$BCStartTime), as.numeric(dt$BCStopTime))) :
>   NAs introduced by coercion
> 2: In order(c(as.numeric(dt$BCStartTime), as.numeric(dt$BCStopTime))) :
>   NAs introduced by coercion
> > numeric_time<-c(as.numeric(dt$BCStartTime),as.numeric(dt$BCStopTime))[obs_order]
> Warning messages:
> 1: NAs introduced by coercion
> 2: NAs introduced by coercion
> > nobs<-diff(range(numeric_time))/3600
> > # find the linear approximation of charge state by hours
> > hourly_SoC <- approx(numeric_time,
> +                    c(dt$Starting_SoC_of_12,dt$Ending_SoC_of_12)[obs_order],n=nobs)
> Error in approx(numeric_time, c(dt$Starting_SoC_of_12, dt$Ending_SoC_of_12)[obs_order],  :
>   need at least two non-NA values to interpolate
>