[R] format() method

Don MacQueen macq at llnl.gov
Fri Apr 16 16:52:43 CEST 2010


Were you expecting "01", and is that why you are puzzled?

See ?strftime and the explanation of the %U format. It depends on 
where the first Sunday of the year happens to fall.

-Don

At 5:28 AM -0800 4/16/10, kafkaz wrote:
>Hello,
>I use format() function to get number of the week, like this:
>format(tmp,'%U')
>Recently, I have spotted something bizarre. For example, I have such object:
>(index(tmp$x.delta['2009'][1:16]))
>  [1] "2009-01-02 CET"  "2009-01-09 CET"  "2009-01-16 CET"  "2009-01-23 CET"
>  [5] "2009-01-30 CET"  "2009-02-06 CET"  "2009-02-13 CET"  "2009-02-20 CET"
>  [9] "2009-02-27 CET"  "2009-03-06 CET"  "2009-03-13 CET"  "2009-03-20 CET"
>[13] "2009-03-27 CET"  "2009-04-03 CEST" "2009-04-09 CEST" "2009-04-17 CEST"
>dput(index(tmp$x.delta['2009'][1:16]),'%U',file='as.date')
>structure(c(1230850800, 1231455600, 1232060400, 1232665200, 1233270000,
>1233874800, 1234479600, 1235084400, 1235689200, 1236294000, 1236898800,
>1237503600, 1238108400, 1238709600, 1239228000, 1239919200), tzone =
>structure("", .Names = "TZ"), class = c("POSIXt",
>"POSIXct"))
>To get number of the week I run:
>format(index(tmp$x.delta['2009'][1:16]),'%U')
>Here is the output - the weird thing is, that the first number of the week
>is 00.
>  [1] "00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "10" "11" "12" "13"
>"14"
>[16] "15"
>
>Is it the bug, my mistake or it is supposed to by like that?
>Thank you,
>kafka
>--
>View this message in context: 
>http://*n4.nabble.com/format-method-tp1999753p1999753.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>R-help at r-project.org mailing list
>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.


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062



More information about the R-help mailing list