R V2.0.1 on Windows XP.
I have read the help pages on strptime() over and over, but can't
understand why strptime() is producing the following results.
> v <- format("2002-11-31", format="%Y-%m-%d")
> v
[1] "2002-11-31"
> factor(v, levels=v)
[1] 2002-11-31
Levels: 2002-11-31
> x <- strptime("2002-11-31", format="%Y-%m-%d")
> x
[1] "2002-12-01"
> factor(x, levels=x)
[1] <NA> <NA> <NA> <NA> <NA> <NA> <NA>
<NA> <NA>
Levels: 2002-12-01 NA NA NA NA NA NA NA NA
Tim C
The result of strptime is a 9-element list. From the help page
Value:
'strptime' turns character representations into an object of class
'"POSIXlt"'.
See Also:
DateTimeClasses for details of the date-time classes; 'locales' to
query or set a locale.
Try ?DateTimeClasses.
On Wed, 1 Dec 2004, Tim Churches wrote:
> R V2.0.1 on Windows XP.
>
> I have read the help pages on strptime() over and over, but can't
> understand why strptime() is producing the following results.
>
> > v <- format("2002-11-31", format="%Y-%m-%d")
> > v
> [1] "2002-11-31"
> > factor(v, levels=v)
> [1] 2002-11-31
> Levels: 2002-11-31
> > x <- strptime("2002-11-31", format="%Y-%m-%d")
> > x
> [1] "2002-12-01"
> > factor(x, levels=x)
> [1] <NA> <NA> <NA> <NA> <NA> <NA>
<NA> <NA> <NA>
> Levels: 2002-12-01 NA NA NA NA NA NA NA NA
I can't understand why you are trying to turn a classed object into a
factor.
--
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
BXC (Bendix Carstensen)
2004-Dec-01 09:52 UTC
[R] Unable to understand strptime() behaviour
Try to say: class(x) unclass(x) and it will dawn on you what goes on. ---------------------- Bendix Carstensen Senior Statistician Steno Diabetes Center Niels Steensens Vej 2 DK-2820 Gentofte Denmark tel: +45 44 43 87 38 mob: +45 30 75 87 38 fax: +45 44 43 07 06 bxc at steno.dk www.biostat.ku.dk/~bxc ----------------------> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Tim Churches > Sent: Tuesday, November 30, 2004 11:37 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Unable to understand strptime() behaviour > > > R V2.0.1 on Windows XP. > > I have read the help pages on strptime() over and over, but > can't understand why strptime() is producing the following results. > > > v <- format("2002-11-31", format="%Y-%m-%d") > > v > [1] "2002-11-31" > > factor(v, levels=v) > [1] 2002-11-31 > Levels: 2002-11-31 > > x <- strptime("2002-11-31", format="%Y-%m-%d") > > x > [1] "2002-12-01" > > factor(x, levels=x) > [1] <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> > Levels: 2002-12-01 NA NA NA NA NA NA NA NA > > Tim C > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read > the posting guide! http://www.R-project.org/posting-guide.html >
Tim,
which aspect of the results? November has 30 days :) What is your goal?
(I'm guessing) try:
x <- as.POSIXct(strptime("2002-11-31",
format="%Y-%m-%d"))
see e.g.
https://stat.ethz.ch/pipermail/r-help/2003-May/032823.html
I hope that this helps,
Andrew.
On Wed, Dec 01, 2004 at 09:36:37AM +1100, Tim Churches
wrote:> R V2.0.1 on Windows XP.
>
> I have read the help pages on strptime() over and over, but can't
> understand why strptime() is producing the following results.
>
> > v <- format("2002-11-31", format="%Y-%m-%d")
> > v
> [1] "2002-11-31"
> > factor(v, levels=v)
> [1] 2002-11-31
> Levels: 2002-11-31
> > x <- strptime("2002-11-31",
format="%Y-%m-%d")
> > x
> [1] "2002-12-01"
> > factor(x, levels=x)
> [1] <NA> <NA> <NA> <NA> <NA> <NA>
<NA> <NA> <NA>
> Levels: 2002-12-01 NA NA NA NA NA NA NA NA
>
> Tim C
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
--
Andrew Robinson Ph: 208 885 7115
Department of Forest Resources Fa: 208 885 6226
University of Idaho E : andrewr at uidaho.edu
PO Box 441133 W : http://www.uidaho.edu/~andrewr
Moscow ID 83843 Or: http://www.biometrics.uidaho.edu
No statement above necessarily represents my employer's opinion.
Hi Tim On 1 Dec 2004 at 9:36, Tim Churches wrote:> R V2.0.1 on Windows XP. > > I have read the help pages on strptime() over and over, but can't > understand why strptime() is producing the following results. > > > v <- format("2002-11-31", format="%Y-%m-%d") > > v > [1] "2002-11-31" > > factor(v, levels=v) > [1] 2002-11-31 > Levels: 2002-11-31 > > x <- strptime("2002-11-31", format="%Y-%m-%d") > > x > [1] "2002-12-01" > > factor(x, levels=x) > [1] <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> > Levels: 2002-12-01 NA NA NA NA NA NA NA NAThis is due to difference in POSIXlt and POSIXct see> length(factor(x, levels=x))[1] 9> y<-as.POSIXct(x) > factor(y, levels=y)[1] 2002-12-01 Levels: 2002-12-01 I do now the result but I do not now the intimate details about classes. Cheers Petr> > Tim C > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz