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
<roslina...@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
>
______________________________________________
R-help@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.

Reply via email to