Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Format to find day of week not working in Windows

I'm new to R. I have Windows PC at work and Ubuntu Linux at home. I'm try to figure out why my code doesn't work in windows R. Im trying to find the day(numeric) of the week for a given date. Using format, format(Sys.time(), "%u")
It works in Linux not on Windows? Am I missing something, I have added a simple code and session info from both PC's.

Output from my Windows 7 PC with R 3.01

sessionInfo() 
R version 3.0.1 (2013-05-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    
LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base  

format(Sys.time(), "%u") 
[1] ""   

Sys.time()  
[1] "2013-09-22 10:34:00 CDT"

Output from my LINUX PC with R 3.01

sessionInfo()  
R version 3.0.1 (2013-05-16)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
[3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
[5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
[7] LC_PAPER=C                 LC_NAME=C                 
[9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     
loaded via a namespace (and not attached)
[1] tools_3.0.1   

format(Sys.time(),"%u")  
[1] "7"   

Sys.time()  
[1] "2013-09-22 10:34:15 CDT" 
like image 423
Rada Krish Avatar asked Sep 22 '13 23:09

Rada Krish


1 Answers

This is R (on Windows)'s documented behavior.

For details, see ?strptime (I know, probably not the first place you might think to look ;-) which documents the date-time conversion specifications available in R. Under Details, an initial list of specifications found on all OSes is followed by a section that reads:

Also defined in the current standards but less widely implemented (e.g. not for output on Windows) are

‘%C’ Century (00-99): the integer part of the year divided by 100.

[ . . . many snipped lines . . .]

‘%u’ Weekday as a decimal number (1-7, Monday is 1).

[ . . . more snipped lines . . .]

The closest substitutes in format are:

%w Weekday as decimal number (0–6, Sunday is 0).

%a Abbreviated weekday name in the current locale. (Also matches full name on input.)

%A Full weekday name in the current locale. (Also matches abbreviated name on input.)

like image 159
Josh O'Brien Avatar answered Sep 21 '22 09:09

Josh O'Brien