[Rd] Month recognition issue
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Sep 16 14:55:17 CEST 2005
On Wed, 7 Sep 2005, Sebastien Durand wrote:
> Dear all,
>
> I am running
> R : Copyright 2005, The R Foundation for Statistical Computing
> Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0
> Under Mac os X, a french version!
There is no `french version', but you may be in a French locale.
> I am preparing a package and I got the following issue
>
> I am trying to read dates that are written in
> english and have them recognized by R using
> as.Date function.
>
> I realized strangely that when I type
>> month.abb
> [1] "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct"
> [11] "Nov" "Dec"
>
> I get the abbreviated english version of every month
>
>> x <- c("1-jan-1960", "2-feb-1960",
>> "31-mar-1960", "30-apr-1960","2-may-1960",
>> "31-jun-1960", "30-jul-1960","2-aug-1960",
>> "31-sep-1960", "30-oct-1960", "30-nov-1960",
>> "30-dec-1960");
>> strptime(x, "%d-%b-%Y")
> [1] "1960-01-01" NA "1960-03-31" NA
> [5] NA NA "1960-07-30" NA
> [9] "1960-10-01" "1960-10-30" "1960-11-30" NA
>
> It is only once I have found through trial an
> error the french abbreviation, that I got a match
> for every month.
>
>> x <- c("1-jan-1960", "2-fév-1960",
>> "31-mar-1960", "30-avr-1960","2-mai-1960",
>> "31-jui-1960", "30-jul-1960","2-aoû-1960",
>> "31-sep-1960", "30-oct-1960", "30-nov-1960",
>> "30-déc-1960");
>> strptime(x, "%d-%b-%Y")
> [1] "1960-01-01" "1960-02-02" "1960-03-31" "1960-04-30"
> [5] "1960-05-02" "1960-07-01" "1960-07-30" "1960-08-02"
> [9] "1960-10-01" "1960-10-30" "1960-11-30" "1960-12-30"
>
> I got simply two questions:
>
> First, why since R was install on a french system
> the month.abb command didn't give me the french
> abbreviations.
Did you read the help page, as we do ask?
* 'month.abb': the three-letter abbreviations for the English
month names;
* 'month.name': the English names for the months of the year;
> Secondly, since I am producing a package, I would
> like to know how can I tell R to momentairly use
> the english abbreviations instead of the french
> ones...
To use them for what? If you mean in strptime, set the locale you want.
There is an example on the help page!
Please do remember to read the help pages before posting.
--
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-devel
mailing list