[R] colClasses

Kerpel, John John.Kerpel at infores.com
Wed Jun 21 22:09:56 CEST 2006


Peter:

Thanks - I'll try both approaches.  The examples clear things up a bit.

John

-----Original Message-----
From: pd at pubhealth.ku.dk [mailto:pd at pubhealth.ku.dk] On Behalf Of Peter Dalgaard
Sent: Wednesday, June 21, 2006 3:04 PM
To: Kerpel, John
Cc: r-help at stat.math.ethz.ch
Subject: Re: [R] colClasses

"Kerpel, John" <John.Kerpel at infores.com> writes:

> Hi Folks!
> 
>  
> 
> I'm reading in some data from a .csv file that has a date column.
> 
>  
> 
> How do I use colClasses to get read.csv to recognize the date column?
> The documentation on this seems to be nil - 
> 
> And yes, I've read help and R Data Import/Export and can't figure out
> what the colClasses syntax is.

1. It may be easier just to read the date field as factor or character
   and convert using as.Date afterwards. If a format is needed, this
   is actually the only way.

2. colClasses is a character vector, possibly named, so

   cls <- rep(NA,17)
   cls[3] <- "Date"
   read.csv(...., colClasses=cls, ....)

   or

   read.csv(...., colClasses=c(mydate="Date"), ....)

   should work (assuming that the variable in question is called
   "mydate" and is in the 3 of 17 columns). This is documented in
   ?read.csv.

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)                  FAX: (+45) 35327907



More information about the R-help mailing list