[R] Datetime conversion

Philipp Pagel p.pagel at wzw.tum.de
Fri Sep 18 19:28:33 CEST 2009


On Fri, Sep 18, 2009 at 04:32:27AM -0700, premmad wrote:
> 
> Sorry for confusing you all with my inexperienced posting .
> I tried as u said if you have 9 rows in the data it is working fine but
> please try out the same example as you have suggested earlier with morethan
> 9 rows.
> 
> I tried it as following
> datetime <-c(
> + "01OCT1987:00:00:00.000",
> +  "12APR2004:00:00:00.000",
> +   "01DEC1987:00:00:00.000",
> +  "01OCT1975:00:00:00.000",
> +   "01AUG1979:00:00:00.000",
> +  "26JUN2003:00:00:00.000",
> +  "01JAN1900:00:00:00.000",
> +  "13MAY1998:00:00:00.000",
> +  "30SEP1998:00:00:00.000",
> +  "30SEP1998:00:00:00.000",
> +  "30SEP1998:00:00:00.000",
> +  "30SEP1998:00:00:00.000") 
> dt <- as.data.frame(datetime) 
> 
> dt$date<-strptime(as.character(dt$datetime),"%d%b%Y") 
> 
> and got the following error :
> 
> Error in `$<-.data.frame`(`*tmp*`, "date", value = list(sec = c(0, 0,  : 
>   replacement has 9 rows, data has 12.

Oops - sorry you are right. There is a Problem with inserting the
object. Try this instead:

dt$date <- as.Date(dt$datetime, "%d%b%Y")

cu
	Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://webclu.bio.wzw.tum.de/~pagel/




More information about the R-help mailing list