Skip to content
Back to formatted view

Raw Message

Message-ID: <201006081213.28870.anand.chirag@gmail.com>
Date: 2010-06-08T06:43:28Z
From: Chirag Anand
Subject: About timeDate Problem
In-Reply-To: <1275830652116-2244985.post@n4.nabble.com>

On Sunday 06 Jun 2010 6:54:12 pm Guy Green wrote:
> I may be missing something on this, but it seems timeDate is quite
>  difficult to work with.  For example, the following code shows some dates
>  working, and others not, but it is hard to see what the difference is
>  except that timeDate has difficulty dealing with single digit dates:
> 
> timeDate("6/7/2010", format = "%m/%d/%Y")  #works fine
> timeDate("5/28/2010", format = "%m/%d/%Y")  #works fine
> timeDate(c("6/7/2010", "5/28/2010"), format = "%m/%d/%Y")  #doesn't work. 
>  I have no idea why the dates work on their own (above), but not together.
>  timeDate(c("06/07/2010", "05/28/2010"), format = "%m/%d/%Y")  #works - so
>  the single/double issue seems to be the cause of the problem
> timeDate(c("06-07-2010", "05-28-2010"), format = "%m-%d-%Y")  #works fine
> 
> Could you just use as.Date?  Does this get you what you wanted?
> 
> date <- read.csv("D:/date.csv",header=T,sep=",")
> date2 = as.Date(date$Date, format = "%m/%d/%Y")
> date2
 
If you still wants to use timeDate class, you can convert from Date class:
  dateNew <- as.timeDate(date2)
  dateNew
 
Probably, it has difficulty dealing with string of characters but from vector of "Date", 
it works fine.
 
-- 
Regards
Chirag Anand