Dear list, I want to create a POSIX time vector as follows: day <- as.character("110809") time.t <- 1:3600 t.min <- time.t %/% 60 t.sec <- time.t-t.min*60 DATE <- as.POSIXct(strptime(paste(day,t.min,t.sec),"%y%m%d %M%S")) Tail(DATE) The problem is that the last element (3600) returns a NA and I don't understand why. 600, 1200, 2400 no problem, only 3600. Any helpful advice is highly appreciated :) Cheers, Jacqueline [[alternative HTML version deleted]]
This should be due to the fact that "110809 60 0" is not interpreted as a valid time value. You probably want to have time.t <- 0:3599 rather than time.t <- 1:3600 if you want one value for each second in the hour, starting from 00:00:00 and running to 00:59:59. 00:60:00 is not a proper time value. On Thu, Sep 1, 2011 at 7:18 AM, J. Augusiak <jaugusiak@googlemail.com>wrote:> Dear list, > > > > I want to create a POSIX time vector as follows: > > > > day <- as.character("110809") > > time.t <- 1:3600 > > t.min <- time.t %/% 60 > > t.sec <- time.t-t.min*60 > > DATE <- as.POSIXct(strptime(paste(day,t.min,t.sec),"%y%m%d %M%S")) > > Tail(DATE) > > > > > > The problem is that the last element (3600) returns a NA and I don't > understand why. 600, 1200, 2400 no problem, only 3600. Any helpful advice > is > highly appreciated :) > > > > Cheers, > > > > Jacqueline > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >-- ___________________________ Luke Miller Postdoctoral Researcher Marine Science Center Northeastern University Nahant, MA (781) 581-7370 x318 [[alternative HTML version deleted]]
try this:> myDate <- as.POSIXct(day, format = "%y%m%d") > myDate[1] "2011-08-09 EDT"> myDate <- myDate + 0:3600 > str(myDate)POSIXct[1:3601], format: "2011-08-09 00:00:00" "2011-08-09 00:00:01" "2011-08-09 00:00:02" ...>On Thu, Sep 1, 2011 at 7:18 AM, J. Augusiak <jaugusiak at googlemail.com> wrote:> Dear list, > > > > I want to create a POSIX time vector as follows: > > > > day ? ?<- as.character("110809") > > time.t <- 1:3600 > > t.min ?<- time.t %/% 60 > > t.sec ?<- time.t-t.min*60 > > DATE ? <- as.POSIXct(strptime(paste(day,t.min,t.sec),"%y%m%d %M%S")) > > Tail(DATE) > > > > > > The problem is that the last element (3600) returns a NA and I don't > understand why. 600, 1200, 2400 no problem, only 3600. Any helpful advice is > highly appreciated :) > > > > Cheers, > > > > Jacqueline > > > > > > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > 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. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?