IniziaInizia gratis

What day is it?

R has a lot to offer in terms of dates and times. The two main classes of data for this are Date and POSIXct. Date is used for calendar date objects like "2015-01-22". POSIXct is a way to represent datetime objects like "2015-01-22 08:39:40 EST", meaning that it is 40 seconds after 8:39 AM Eastern Standard Time.

In practice, the best strategy is to use the simplest class that you need. Often, Date will be the simplest choice. This course will use the Date class almost exclusively, but it is important to be aware of POSIXct as well for storing intraday financial data.

In the exercise below, you will explore your first date and time objects by asking R to return the current date and the current time.

Questo esercizio fa parte del corso

Intermediate R for Finance

Visualizza il corso

Istruzioni dell'esercizio

  • Type Sys.Date() to have R return the current date.
  • Type Sys.time() to have R return the current date and time. Notice the difference in capitalization of Date vs time.
  • Store Sys.Date() in the variable today.
  • Use class() on today to confirm its class.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# What is the current date?
___

# What is the current date and time?
___

# Create the variable today
today <- ___


# Confirm the class of today
___
Modifica ed esegui il codice