[R] Odd time conversion glitch

From: Pat Carroll <docpat2511_at_yahoo.com>
Date: Thu, 27 Dec 2007 11:31:36 -0800 (PST)


Hello, all.

I ran across an odd problem while working in R 2.6.0. The command line text follows. Basically, I attempted to convert a character vector of length 13 (in a data frame with 13 rows) from a character representation of dates to a POSIX representation using strptime. strptime returned a vector of length 9, which appears to contain 13 values (!) in the appropriate format.

I can't find any way to convince the strptime output that it has 13 values . . . even though (for example) posixvector[1:13] returns 13 values, anothervectorof length13<-posixvector[1:13] produces a length mismatch error.

Can anyone help diagnose this, or work around it?

Many thanks,
~Pat Carroll.

> Dataset$DateFilled

 [1] "10/20/2005" "11/4/2005" "11/18/2005" "12/2/2005" "4/3/2006" "6/5/2006" "7/14/2006" "4/27/2007" "5/7/2007" "7/17/2007" "2/14/2005" [12] "2/14/2005" "2/21/2005"
> datefilledpos<-strptime(Dataset$DateFilled,format="%m/%d/%Y")
> datefilledpos

 [1] "2005-10-20" "2005-11-04" "2005-11-18" "2005-12-02" "2006-04-03" "2006-06-05" "2006-07-14" "2007-04-27" "2007-05-07" "2007-07-17" "2005-02-14" [12] "2005-02-14" "2005-02-21"
> length(datefilledpos)

[1] 9
> length(Dataset$DateFilled)

[1] 13
> datefilledpos[1:13]

 [1] "2005-10-20" "2005-11-04" "2005-11-18" "2005-12-02" "2006-04-03" "2006-06-05" "2006-07-14" "2007-04-27" "2007-05-07" "2007-07-17" "2005-02-14" [12] "2005-02-14" "2005-02-21"
> Dataset$DateFilled<-datefilledpos

Error in `$<-.data.frame`(`*tmp*`, "DateFilled", value = list(sec = c(0, :   replacement has 9 rows, data has 13
> Dataset$DateFilled<-datefilledpos[1:13]
Error in `$<-.data.frame`(`*tmp*`, "DateFilled", value = list(sec = c(0, :   replacement has 9 rows, data has 13
>
 

Pat Carroll.
what matters most is how well you walk through the fire. bukowski.



Be a better friend, newshound, and

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 27 Dec 2007 - 19:34:39 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 27 Dec 2007 - 22:30:20 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.