Glad to know it isn't just me!  I couldn't use Phil's data.frame method since 
my real problem went from a POSIXct object to a large matrix where I used rbind 
and then back to POSIXct.  Jim's function worked great on converting the final 
product back to the proper date.

Thanks!

Tim


Tim Clark
Department of Zoology 
University of Hawaii


--- On Fri, 2/19/10, jim holtman <jholt...@gmail.com> wrote:

> From: jim holtman <jholt...@gmail.com>
> Subject: Re: [R] r help date format changes with c() vs. rbind()
> To: "Tim Clark" <mudiver1...@yahoo.com>
> Cc: r-help@r-project.org
> Date: Friday, February 19, 2010, 12:19 PM
> I have used the following function to
> convert to POSIXct from a numeric without any
> problems:
>  
> > unix2POSIXct <- function (time)  
> structure(time, class = c("POSIXt",
> "POSIXct"))
> > 
> > unix2POSIXct(946764000)
> [1] "2000-01-01 17:00:00 EST"
> > 
> 
> 
> 
> 
> On Fri, Feb 19, 2010 at 4:07 PM,
> Tim Clark <mudiver1...@yahoo.com>
> wrote:
> 
> Dear
> List,
> 
> I am having a problem with dates and I would like to
> understand what is going on.  Below is an example.  I can
> produce a date/time using as.POSIXct, but I am trying to
> combine two as.POSIXct objects and keep getting strange
> results.  I thought I was using the wrong origin, but
> according to structure(0,class="Date") I am not
> (see below).  In my example a is a simple date/time object,
> b combines it using rbind(), c converts b to a date/time
> object again using as.POSIXct and gives the incorrect time,
> and d combines a using c() and gives the correct time.  Why
> doesn't c give me the correct answer?
> 
> 
> Thanks,
> 
> Tim
> 
> 
> > a<-as.POSIXct("2000-01-01 12:00:00")
> > a
> [1] "2000-01-01 12:00:00 HST"
> 
> > b<-rbind(a,a)
> > b
>       [,1]
> a 946764000
> a 946764000
> 
> 
> > c<-as.POSIXct(b,origin="1970-01-01")
> > c
> [1] "2000-01-01 22:00:00 HST"
> [2] "2000-01-01 22:00:00 HST"
> 
> > d<-c(a,a)
> > d
> [1] "2000-01-01 12:00:00 HST"
> 
> [2] "2000-01-01 12:00:00 HST"
> 
> 
> > structure(0,class="Date")
> [1] "1970-01-01"
> 
> 
> Tim Clark
> Department of Zoology
> University of Hawaii
> 
> ______________________________________________
> 
> 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.
> 
> 
> 
> -- 
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
> 
> What is the problem that you are trying to solve?
> 
> 




______________________________________________
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.

Reply via email to