« R wins 2009 KDD Cup "slow challenge" | Main | Implementing Decision Tree Bagging models in R: A Walkthrough »

June 02, 2009

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a010534b1db25970b011570adb3c3970b

Listed below are links to weblogs that reference Converting time zones in R: tips, tricks and pitfalls:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

And when you think you have it all figured out do (inspired by help("DateTimeClasses")):

> d <- c("2005-12-31 23:59:59", "2005-12-31 23:59:60", "2006-01-01 00:00:00")
> as.POSIXct(d,tz="UTC")
[1] "2005-12-31 23:59:59 UTC" "2006-01-01 00:00:00 UTC"
[3] "2006-01-01 00:00:00 UTC"
> as.POSIXlt(d,tz="UTC")
[1] "2005-12-31 23:59:59 UTC" "2005-12-31 23:59:60 UTC"
[3] "2006-01-01 00:00:00 UTC"

:-)

Also note that DST rules are implemented by your operating system so if you upgrade your system the external representation of POSIXct objects may change. I spent a couple of weeks debugging this once. Use POSIXlt for legal dates (“the contract/assembly line/whatever starts...”) and POSIXct for events in the universe (asteroid impacts, say).

Try tz="PST8PDT" for the daylight savings time in the pacific time zone. On my mac you can see all the available time zones in the /usr/share/zoneinfo directory, I'm pretty sure that would be similar on most unix based systems. Not sure where you would find the list on Windows.

Also note this is highly dependent on the sytem you are using the code on so this is not really portable code. I usually store everything as GMT to try and keep things constistent and as portable as possible. Also be aware of the data you are getting, I wasted a day on finding out a data set was stored strictly in PST and never adjusted for daylight savings once.

I want to find a way to find a maximum value between two columns (a,b) and create a third column in a dataframe c = max(a,b). See example below.

I tried using apply but it does not work because it coerces the data into a matrix/character conversion. How can this be done?

> mydf=data.frame(a=rep(Sys.time()+rnorm(1),10), b=rep(Sys.time(), 10))
> mydf
a b
1 2009-06-26 08:53:36 2009-06-26 08:53:35
2 2009-06-26 08:53:36 2009-06-26 08:53:35
3 2009-06-26 08:53:36 2009-06-26 08:53:35
4 2009-06-26 08:53:36 2009-06-26 08:53:35
5 2009-06-26 08:53:36 2009-06-26 08:53:35
6 2009-06-26 08:53:36 2009-06-26 08:53:35
7 2009-06-26 08:53:36 2009-06-26 08:53:35
8 2009-06-26 08:53:36 2009-06-26 08:53:35
9 2009-06-26 08:53:36 2009-06-26 08:53:35
10 2009-06-26 08:53:36 2009-06-26 08:53:35

That's awesome! Exactly the code I was looking for! Thanks, dude!

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment

Revolution Analytics
Information about Revolution R

Got comments or suggestions for the blog editor?
Email David Smith.
Follow revodavid on Twitter Follow David on Twitter: @revodavid
R Contest - Click to Enter

R links

Recommended Sites

Search Revolutions Blog