Re: [R] CSV file and date. Dates are read as factors!

From: Jorge de la Vega Gongora <>
Date: Thu 28 Jul 2005 - 23:57:36 EST

Use the package chron. Before importing the data to R from the cvs file, convert dates to numeric format. Dates are just a sequence from a starting point. I use the following to work with dates. Asuming you have a column in your cvs file with header "date":
 options(chron.origin=c(month=12,day=31,year=1899))  x <- read.csv("../bla/bla.csv")
x$date <- chron(x$date,format="y-m-d")
 Or if you have your cvs file with labels like "02/03/2005", then replace the last line with:
 x$date <- chron(as.character(x$date),format="y-m-d")  Then you can use your field date to do date operations  Hope this is useful.

 On 7/27/05, 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
> John Sorkin M.D., Ph.D.
> Chief, Biostatistics and Informatics
> Baltimore VA Medical Center GRECC and
> University of Maryland School of Medicine Claude Pepper OAIC
> University of Maryland School of Medicine
> Division of Gerontology
> Baltimore VA Medical Center
> 10 North Greene Street
> GRECC (BT/18/GR)
> Baltimore, MD 21201-1524
> 410-605-7119
> ______________________________________________
> mailing list
> PLEASE do read the posting guide!

        [[alternative HTML version deleted]] mailing list PLEASE do read the posting guide! Received on Fri Jul 29 00:14:42 2005

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