[R] Extract time and state of charge (Start and End) and Count

roslinazairimah zakaria ro@||n@ump @end|ng |rom gm@||@com
Thu Jul 21 07:17:32 CEST 2022


Hi Jim,
I have tried your code and am able to understand most of the code and apply
it to the whole data set.
But I am not sure about this part:

colnames(result) <- paste(0:11,1:12,sep="-")

What is at 0-1, 1, 0? Number of cars at hour 1 at state of charge between 0
and 1?

For 11-12, 1, 268? Number of cars at hour 1 at state of charge between 11
and 12?

> print(result)

   0-1 1-2 2-3 3-4 4-5 5-6 6-7 7-8 8-9 9-10 10-11 11-12

1    0   0   1   0   7   4   2   6  20   19    38   268

2    1   0   5   4   2   9   4  10  17   24    33   255

3    0   0   2   1   8   7   7  16  28   31    49   215

4    0   2   6   3   4   5  15  24  53   38    43   171

5    2   2  13   6  21  19  28  35  43   44    42   109

6    0   4  16  16  29  43  36  38  31   55    48    47

7    0   6  15  23  33  35  56  55  39   47    26    29

8    3   7  15  19  24  46  58  39  37   32    48    36

9    1   6  13  14  28  29  31  52  44   39    46    61

10   3   4   8  12  27  22  33  38  54   66    51    47

11   4   6   7  12  16  33  37  28  53   52    47    69

12   2   6  10  16  17  34  32  51  34   51    56    56

13   0   2  12  12  21  33  30  34  48   48    56    69

14   1   3  17  10  17  28  37  47  46   54    54    50

15   2   5  14  26  21  30  47  53  53   35    44    35

16   3   7  14  24  29  40  39  42  40   50    44    33

17   0   8  28  24  39  36  41  42  38   41    34    34

18   4  11  18  26  25  30  53  40  49   39    36    34

19   4   6  16  19  22  34  47  43  37   48    39    49

20   5   4  10  17  18  30  25  41  42   57    44    72

21   1   4   7  14  19  23  33  22  34   37    53   118

22   0   5   7  19  16  24  24  24  26   36    37   146

23   2   7   6  11  16  15  19  21  16   29    39   183

24   0   0   0   0   0   0   0   0   0    0     0     0



On Wed, Jul 20, 2022 at 8:49 AM Jim Lemon <drjimlemon using gmail.com> wrote:

> 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 using 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
> >
>


-- 
*Roslinazairimah Zakaria*
*Tel: +609-5492370; Fax. No.+609-5492766*

*Email: roslinazairimah using ump.edu.my <roslinazairimah using ump.edu.my>;
roslinaump using gmail.com <roslinaump using gmail.com>*
Faculty of Industrial Sciences & Technology
University Malaysia Pahang
Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia

	[[alternative HTML version deleted]]



More information about the R-help mailing list