[R] dates by week multiple years

Jim Lemon drj|m|emon @end|ng |rom gm@||@com
Wed Feb 6 07:16:51 CET 2019


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 <marlinkcox using gmail.com> 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]]
>
> ______________________________________________
> R-help using 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.



More information about the R-help mailing list