2019-06-02

How to get week numbers from dates in R?


Problem

We would like to calculate the week number of a given date in R.

c("2014-03-16", "2014-03-17","2014-03-18", "2014-01-01")
[1] "2014-03-16" "2014-03-17" "2014-03-18" "2014-01-01"

Solution

Using the function strftime passing the argument %V to obtain the week of the year as decimal number (01–53) as defined in ISO 8601. (More details in the documentarion: ?strftime)

strftime(c("2014-03-16", "2014-03-17","2014-03-18", "2014-01-01"), format = "%V")
[1] "11" "12" "12" "01"

Related entries

References

No hay comentarios:

Publicar un comentario

Nube de datos