[R] strptime problems

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Sep 3 15:26:41 CEST 2004


I suspect rather a locale problem which Date and chron will also have.

You are looking for an abbreviated month name (%b).  What language is the 
object ccc in?  What language is your computer in?  See the example in
?strptime

     ## read in date info in format 'ddmmmyyyy'
     ## This will give NA(s) in some locales; setting the C locale
     ## as in the commented lines will overcome this on most systems.
     ## lct <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")
     x <- c("1jan1960", "2jan1960", "31mar1960", "30jul1960")
     z <- strptime(x, "%d%b%Y")

Looking for English abbreviations in a Norwegian file, for example, will 
not work and give NAs.

On Fri, 3 Sep 2004, Thomas Petzoldt wrote:

> Per Wiklund wrote:
> 
>  >
>  > Hi, I'm experiencing a problem with strptime. (R 1.9.1 on a Win2000
>  > machine)
> 
> [...]
> 
>  > strptime(as.character(ccc[[11]]$TradeDateTime[161522]),
>  >    "%d-%b-%y:%H:%M:%S")
>  > [1] NA
> 
> [...]
> 
> Hello,
> 
> unfortunately, your code does not show what data are in the object ccc, 
> so an exact diagnosis is almost impossible. However, I suspect you have 
> timezone problems which are common on Windows computers. If you don't 
> need timezone calculations I suggest to use the Date class (uppercase 
> "D") or the chron package instead of the POSIX classes, see the last 
> issue of R-News:
> 
> http://cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf
> 
> Thomas P.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list