dates by week multiple years

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

dates by week multiple years

Marlin Keith Cox
Hello all, I did not attach data as this is probably simple answer that I
cannot find.

I am collecting daily data and would like to plot the data by week but now
that we are into the new year, my plots started over with 01 after the last
week of the year.  How can I continuously keep adding weeks such as 53, 54,
55, 56, etc. instead of starting over?

Below has worked for me until we moved into 2019.

data$Date    <- as.Date(data$TIMESTAMP,format="%m/%d/%y  %H:%M")
data$Week1    <- strftime(data$Date,format = "%V")
data$Week<-as.factor(data$Week1)

Keith

M. Keith Cox, Ph.D.
Principal
MKConsulting
17415 Christine Ave.
Juneau, AK 99801
U.S. 907.957.4606

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: dates by week multiple years

Jim Lemon-4
Hi Keith,
Perhaps you do not want to go with calendar weeks:

365/7 = 52.14

as there are not an even number of weeks in a year, you may want to
plot by week from your initial observation. As you are using as.Date,
you could simply calculate weeks as:

data$Week<-1+as.numeric(data$Date - data$Date[1])%/%7

Jim

On Wed, Feb 6, 2019 at 4:52 PM Marlin Keith Cox <[hidden email]> wrote:

>
> Hello all, I did not attach data as this is probably simple answer that I
> cannot find.
>
> I am collecting daily data and would like to plot the data by week but now
> that we are into the new year, my plots started over with 01 after the last
> week of the year.  How can I continuously keep adding weeks such as 53, 54,
> 55, 56, etc. instead of starting over?
>
> Below has worked for me until we moved into 2019.
>
> data$Date    <- as.Date(data$TIMESTAMP,format="%m/%d/%y  %H:%M")
> data$Week1    <- strftime(data$Date,format = "%V")
> data$Week<-as.factor(data$Week1)
>
> Keith
>
> M. Keith Cox, Ph.D.
> Principal
> MKConsulting
> 17415 Christine Ave.
> Juneau, AK 99801
> U.S. 907.957.4606
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.