[R-SIG-Mac] dates in R
Turner Rolf
r.turner at auckland.ac.nz
Mon Oct 25 01:53:51 CEST 2010
________________________________________
From: David Winsemius [dwinsemius at comcast.net]
Sent: Sunday, 24 October 2010 10:34 a.m.
To: Turner Rolf
Cc: sirmeelo at gmail.com; r-sig-mac at stat.math.ethz.ch
Subject: Re: [R-SIG-Mac] dates in R
On Oct 23, 2010, at 2:09 PM, Turner Rolf wrote:
>
>
> sirmeelo at gmail.com [sirmeelo at gmail.com] wrote:
>
> Hi list,
>
> I am having trouble getting R to read and display dates correctly.
> My dates
> are in the form of day (no space) month (no space) year, for
> example: 250706
> and sometimes 50906.
>
> Any guidance would be appreciated...Thanks.
>
> (1) This question has nothing to do with Mac computers. It should
> have been sent to r-help.
>
> (2) The problem seems to me to be the inconsistency in the number of
> digits representing
> "day", To remedy this, paste on a zero and then remove redundant
> zeroes:
>
> foo <- function(x) {
> x <- paste(0,x,sep="")
> x <- substr(x,nchar(x)-5,nchar(x))
> strptime(x,format="%d%m%y")
> }
>
> x <- c(250706,50906)
> foo(x)
> [1] "2006-07-25" "2006-09-05"
All true. I have had to do steps equivalent to this, but learned from
my experience. I now use colClasses to import dates as "character"
rather than numeric.
This will work unless the dates are whukked (Maori spelling --- I used to say "whucked" until
it was pointed out to me that there is no "c" in the Maori alphabet; this is a dodge to get around
the censorship imposed by "mailmarshal") up in the original file from which they
are imported. :-)
It is good to be a where that R is very powerful in its facilities for manipulating data and a little
understanding of R's capabilities can rescue you from almost any exigency.
cheers,
Rolf
More information about the R-SIG-Mac
mailing list