Skip to content
Related Articles

Related Articles

Convert DataFrame with Date Column to Time Series Object in R

View Discussion
Improve Article
Save Article
  • Last Updated : 23 May, 2021
View Discussion
Improve Article
Save Article

In this article, we will discuss how to convert dataframe with date column to time series object in the R programming language.

Time series object are a series of data points in which each data point is associated with a timestamp. For example, is a price of a stock in the stock market at different points of time. The data for the time series is stored in an R object called time-series object. These are also called as xts / zoo Object.

To convert the given dataframe with the date column to the time series object, the user first needs to import and load the xts package.




The user then needs to call the xts() function with the required parameters the main need to call this function is to create the time-series object in R language and at the end use is.xts() function we will be conforming to the time-series object created by xts() function in R language.

 xts() function is basically used as the constructor for creating an extensible time-series object.


xts(x = NULL, = index(x), frequency = NULL,  unique = TRUE, tzone = Sys.getenv(“TZ”),  …)


  • x:-an object containing the time series data
  • corresponding vector of unique times/dates – must be of a known time-based class.
  • frequency:-numeric indicating the frequency of order.
  • unique:-should index be checked for unique time-stamps?
  • tzone:-time zone of series. This is ignored for Date indices
  • …:-additional attributes to be added.



gfg_date <- data.frame(date = c("2004-05-07","2005-10-12",
gfg_ts <- xts(gfg_date$val, gfg_date$date)


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!