[R] Applying strptime() to a data set or array
aathan_R_1542 at memeplex.com
Tue Mar 7 06:35:24 CET 2006
A$date is already a string, as read from the file. I tried it anyway,
> A$date<-strptime(as.character(A$date),"%Y-%m-%d %H:%M:%s")
Error in "$<-.data.frame"(`*tmp*`, "date", value = list(sec = c(0, 0, :
replacement has 9 rows, data has 3198
Jacques VESLOT wrote:
> maybe you need to transform A$date to character:
> A$date <- strptime(as.character(A$date), ...)
> see also:
> Andrew Athan a écrit :
>> I'm sure this is just the result of a basic misunderstanding of the
>> syntax of R, but I am stumped.
>> A <-
>> 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?
>> R-help at stat.math.ethz.ch mailing list
>> PLEASE do read the posting guide!
More information about the R-help