Re: [R] Dates are read as factors!

From: Marc Schwartz <>
Date: Thu 28 Jul 2005 - 13:25:24 EST

On Wed, 2005-07-27 at 23:07 -0400, John Sorkin wrote:
> I am using read.csv to read a CSV file (produced by saving an Excel file
> as a CSV file). The columns containing dates are being read as factors.
> Because of this, I can not compute follow-up time, i.e.
> Followup<-postDate-preDate. I would appreciate any suggestion that would
> help me read the dates as dates and thus allow me to calculate follow-up
> time.
> Thanks
> John


Depending upon how may columns you are reading, you could:

  1. Use the 'colClasses' argument in read.csv() to specify the data types for each incoming column, one of which is 'Date'


2. Post process the data after importing by using the as.Date() function. See ?as.Date for more information and pay particular attention to the 'format' argument.

My own preference is number 2.

Once the requisite columns are converted to the Date class, you can engage in date based arithmetic, etc.

HTH, Marc Schwartz mailing list PLEASE do read the posting guide! Received on Thu Jul 28 13:31:08 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:34:06 EST