[R] surprising dates

From: ivo welch <ivowel_at_gmail.com>
Date: Sun 04 Jun 2006 - 11:21:02 EST


I wonder if this is an intentional feature or an oversight. in some column summaries or in ifelse operations, apparently I am losing the date property of my vector.

> a <- c(198012, 198101, 198102)
> b <- a*100+31
> c <- as.Date( as.character(b), "%Y%m%d" )

> summary(c)

        Min. 1st Qu. Median Mean 3rd Qu. Max. "1980-12-31" "1981-01-07" "1981-01-15" "1981-01-15" "1981-01-23" "1981-01-31"
> summary( cbind(1:3, c) )

       V1 c

 Min.   :1.0   Min.   :4017
 1st Qu.:1.5   1st Qu.:4025
 Median :2.0   Median :4032
 Mean   :2.0   Mean   :4032
 3rd Qu.:2.5   3rd Qu.:4040
 Max.   :3.0   Max.   :4048
               NA's   :   1


> d <- a*100+28
> e <- as.Date( as.character(d), "%Y%m%d" )
> e

[1] "1980-12-28" "1981-01-28" "1981-02-28"
> c


[1] "1980-12-31" "1981-01-31" NA
> ifelse( is.na(c), e, c )

[1] 4017 4048 4076 # date property is lost

PS: this time I do not need help. I can write my code around this.

regards,

/ivo



R-help@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 Received on Sun Jun 04 11:34:20 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 04 Jun 2006 - 18:10:36 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.