[R] Applying strptime() to a data set or array

Andrew Robinson A.Robinson at ms.unimelb.edu.au
Tue Mar 7 06:45:03 CET 2006


Try prepending as.POSIXct

A[,1] <- as.POSIXct(strptime(A$date,"%Y-%m-%d %H:%M:%s"))

A.

On Mon, Mar 06, 2006 at 11:58:01PM -0500, Andrew Athan wrote:
> 
> I'm sure this is just the result of a basic misunderstanding of the 
> syntax of R, but I am stumped.
> 
> A <- 
> read.table(file="sumByThirtyMinute.csv",sep=",",col.names=c("date","pandl"))
> 
> A now consists of thousands of rows, but A$date is a string...
> ...
> 3183 2006-02-28 12:00:00    548.470
> 3184 2006-02-28 12:30:00    515.240
> 3185 2006-02-28 13:00:00    140.120
> 3186 2006-02-28 13:30:00    450.940
> 3187 2006-02-28 14:00:00    318.570
> ...
> 
> 
> 
> 
> So, I try to convert A$date to a POSIXlt ...
> 
> A[,1]<-strptime(A$date,"%Y-%m-%d %H:%M:%s")
> A$date<-strptime(A$date,"%Y-%m-%d %H:%M:%s")
> 
> 
> which gives me a warning that the length of the array I am trying to 
> replace A$date with is 9 ... but if I print strptime(A$date,"%Y-%m-%d 
> %H:%M:%s"), it clearly has thousands of rows.  Yet, if I ask for 
> length(strptime(A$date,"%Y-%m-%d %H:%M:%s")), I get 9.
> 
> What am I doing wrong?  Do I need to convert the return value of 
> strptime(A$date,"%Y-%m-%d %H:%M:%s") to some array/vector/matrix 
> datatype before attempting to assign it?
> 
> Thanks,
> Andrew
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

-- 
Andrew Robinson  
Department of Mathematics and Statistics            Tel: +61-3-8344-9763
University of Melbourne, VIC 3010 Australia         Fax: +61-3-8344-4599
Email: a.robinson at ms.unimelb.edu.au         http://www.ms.unimelb.edu.au




More information about the R-help mailing list