[R] error message when using strptime

From: Kara Przeczek <przeczek_at_unbc.ca>
Date: Fri, 28 Nov 2008 16:12:54 -0800

I am new to R and have been struggling with the following problem. I apologize if there is an obvious answer that I have missed.  

I bring in a .txt file (pyr_h.txt) that has a DateTime column in the format "yyyy-mm-dd HH:MM" When it comes into R, R does not recognize it as a date/time format.  

     Date Time DateTime N_Wm2 S_Wm2

1   4/1/2008   01:00    2008-04-01 01:00    0.0000    0.00000
2   4/1/2008   02:00    2008-04-01 02:00    0.0000    0.00000
3   4/1/2008   03:00    2008-04-01 03:00    0.0000    0.00000
4   4/1/2008   04:00    2008-04-01 04:00    0.0000    0.00000
5   4/1/2008   05:00    2008-04-01 05:00    0.0000    0.00000
6   4/1/2008   06:00    2008-04-01 06:00    3.1655    2.56175


pyr_h = read.table("H:/MastersInfo/data/Figures/Tables/pyr_h.txt",header = T, sep = "\t")
# convert Date to date format

pyr_h$Date = as.Date(pyr_h$Date, format = "%m/%d/%Y")
# convert DateTime to number format

pyr_h$DateTime = strptime(pyr_h$DateTime, format="%Y-%m-%d %H:%M")  

This strptime command works on another .txt file of mine with the exact same date/time stamps, but when I try it for this file, it gives the error message:  

Error in `$<-.data.frame`(`*tmp*`, "DateTime", value = list(sec = c(0, :   replacement has 9 rows, data has 1570

I tried creating a vector:  

tmp <-strptime(pyr_h$DateTime, format="%m/%d/%Y %H:%M")  

When I queried the length of this vector, it was 9, yet when I print the vector there are 1570 objects. Any idea what is going on here? I have tried formatting the DateTime different ways in Excel, recreating the .txt file, changing the strptime format, and rebooting R yet nothing seems to be working. Thanks SO much!

Kara Przeczek
M.Sc. Candidate NRES - Environmental Science University of Northern B.C.
3333 University Way
Prince George B.C V2N 4Z9
Phone: (250) 960-5427

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 Sat 29 Nov 2008 - 00:14:44 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 Sat 29 Nov 2008 - 01:30:28 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.

list of date sections of archive