12.07.2015 Views

R dummies

R dummies

R dummies

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

An easy way to achieve this is to work with dates in the POSIXlt class,because this type of data is stored internally as a named list, which enables you toextract elements by name. To do this, first convert the Date class:> xlt xlt[1] “1969-07-20 20:17:39 UTC”Next, use the $ operator to extract the different elements. For example, to getthe year, use the following:> xlt$year[1] 69And to get the month, use the following:> xlt$mon[1] 6You can use the unclass() function to expose the internal structure ofPOSIXlt objects.> unclass(xlt)If you run this line of code, you’ll see that POSIXlt objects are really justnamed lists. You get to work with lists in much more detail in Chapter 7.More date and time fun(ctionality)In this chapter, we barely scratch the surface on how to handle dates andtimes in R. You may want to explore additional functionality available in Rand add-on packages by looking at the following:chron: In addition to all the data classes that we cover in this chapter, Rhas a chron class for datetime objects that don’t have a time zone. Toinvestigate this class, first load the chron package with library(chron) andthen read the Help file ?chron.lubridate: You can download the add-on package lubridate fromCRAN. This package provides many functions to make it easier to work withdates. You can download and find more information at http://cran.r-

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!