[R] Time vector in weeks

Gabor Grothendieck ggrothendieck at gmail.com
Fri May 19 00:24:28 CEST 2006


If you are just trying to create a character vector of the form week-year
then

paste(fecha[,2], fecha[,1], sep = "-")

or

 sprintf("%02.0f-%4.0f", fecha[,2], fecha[,1])

will do it (the second will zero fill as well).

or if you are trying to create a vector of class "Date" and then print
that then

dat <- as.Date(sprintf("%4.0f-01-01", fecha[,1])) + 7*fecha[,2]-1
format(dat, "%W-%Y")

(You might need to check that I got the mapping between weeks
and dates right.)

R News 4/1 Help Desk article has more on dates.



On 5/18/06, fernando espindola <fdoespin at gmail.com> wrote:
> Hi User R
>
> I am try to create a date vector with weeks of the year as show in the
> data below,  for a time series of sea surface temperature near to the
> coast (i.e the points from image that are inside the polygon object; the
> first 20 miles from the coast. Any body can tell me how create this
> time vector, i try to use the next code but the error message show:
>
> strftime(c(paste(fecha[,2],"-",fecha[,1],sep="")),format="%W-%Y")
> error......wrong class
>
> Thank in advance
>
>
> fecha<-matrix(c(2002,2002,2002,2002,2002,2002,2002,2002,2002,2002,2002,2002,2002,,2002,2002,2002,2002,2002,
> 2002,2002,2002,2002,2002,2002,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,
> 2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,
> 2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2003,2004,2004,2004,2004,2004,
> 2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,
> 2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,2004,
> 2004,2004,2004,2004,2004,2004,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,
> 2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,
> 2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,2005,29,30,31,32,33,34,35,36,37,
> 38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24
> ,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,1,2,3,4,5,6,7,8,9,10,11,12,13,
> 14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,
> 51,52,53,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,
> 39,40,41,42,43,44,45,46,47,48,49,50,51,52),nrow=181,ncol=2)
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list