[R] strptime problems
Gabor Grothendieck
ggrothendieck at myway.com
Fri Sep 3 17:44:39 CEST 2004
Prof Brian Ripley <ripley <at> stats.ox.ac.uk> writes:
:
: I suspect rather a locale problem which Date and chron will also have.
I don't think chron uses locales so it would likely also be a problem
with Date but not with chron.
In this example, we change the locale to Danish and then display the first
of each of 12 months using chron and Date:
R> lct <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "da")
[1] "Danish_Denmark.1252"
R> chron(paste(1:12,1,2004,sep="/"),out.format="M-D-Y")
[1] Jan-01-2004 Feb-01-2004 Mar-01-2004 Apr-01-2004 May-01-2004 Jun-01-2004
Jul-01-2004 Aug-01-2004 Sep-01-2004 Oct-01-2004 Nov-01-2004 Dec-01-2004
R> format(as.Date(.Last.value),"%B-%d-%Y")
[1] "januar-01-2004" "februar-01-2004" "marts-01-2004" "april-01-
2004" "maj-01-2004" "juni-01-2004" "juli-01-2004"
[8] "august-01-2004" "september-01-2004" "oktober-01-2004" "november-01-
2004" "december-01-2004"
:
: 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.
:
More information about the R-help
mailing list