Loved by learners at thousands of companies
Time series are all around us, from server logs to high frequency financial data. Managing and manipulating ordered observations is central to all time series analysis. The xts and zoo packages provide a set of powerful tools to make this task fast and mistake free. In this course, you will learn everything from the basics of xts to advanced tips and tricks for working with time series data in R.
Introduction to eXtensible Time Series, using xts and zoo for time seriesFree
xts and zoo are just two of the many different types of objects that exist in R. This chapter will introduce the basic objects in xts and zoo and their components, and offers examples of how to construct and examine the data.
First Order of Business - Basic Manipulations
Now that you can create basic xts objects, it's time to see how powerful they can be. This chapter will cover the basics of one of the most useful features of xts: time based subsetting. From there you'll explore additional ways to extract data using time phrases, and conclude with how to do basic operations like adding and subtracting your xts objects.Introducing time based queries50 xpThe ISO-8601 standard50 xpQuerying for dates100 xpExtracting recurring intraday intervals100 xpAlternative extraction techniques50 xpRow selection with time objects100 xpUpdate and replace elements100 xpMethods to find periods in your data50 xpFind the first or last period of time100 xpCombining first and last100 xpMath operations using xts50 xpMatrix arithmetic - add, subtract, multiply, and divide in time!100 xpMath with non-overlapping indexes100 xp
Merging and modifying time series
One of the most important parts of working with time series data involves creating derived time series. To do this effectively, it is critical to keep track of dates and times. In this chapter you will look at how xts handles merging new columns and rows into existing data, how to deal with the inevitable missing observations in time series, and how to shift your series in time.Merging time series50 xpCombining xts by column with merge100 xpCombining xts by row with rbind100 xpWhat types of data can be combined using merge?50 xpHandling missingness50 xpFill missing values using last or previous observation100 xpNA interpolation using na.approx()100 xpLags and differences50 xpCombine a leading and lagging time series100 xpCalculate a difference of a series using diff()100 xpWhat is the key difference in lag between xts and zoo50 xp
Apply and aggregate by time
Now the fun begins! A very common usage pattern for time series is to calculate values for disjoint periods of time or aggregate values from a higher frequency to a lower frequency. For most series, you'll often want to see the weekly mean of a price or measurement. You may even find yourself looking at data that has different frequencies and you need to normalize to the lowest frequency. This chapter is where it all happens. Hang tight, and lets get going!Apply functions by time50 xpFind intervals by time in xts100 xpApply a function by time period(s)100 xpUsing lapply() and split() to apply functions on intervals100 xpSelection by endpoints vs. split-lapply-rbind100 xpConverting periodicity50 xpConvert univariate series to OHLC data100 xpConvert a series to a lower frequency100 xpRolling functions50 xpCalculate basic rolling value of series by month100 xpCalculate the rolling standard deviation of a time series100 xp
Extra features of xts
Now that you are comfortable with most of the core features, its time to explore some of the lesser known (but powerful!) aspects of working with xts. In this final chapter you will use the internals of the index to find repeating itervals, see how xts provides intuitive time zone support, and experiment with ways to explore your data by time - including identifying frequency and coverage in time. Let's finish this course!Index, attributes, and time zones50 xpTime via index()50 xpClass attributes - tclass, tzone, and tformat100 xpTime Zones (and why you should care!)100 xpPeriods, periodicity and timestamps50 xpDetermining periodicity100 xpFind the number of periods in your data100 xpSecret index tools100 xpModifying timestamps100 xpCongratulations!50 xp
PrerequisitesIntermediate R for Finance
DataCamp Content Creator
DataCamp offers interactive R, Python, Spreadsheets, SQL and shell courses. All on topics in data science, statistics, and machine learning. Learn from a team of expert teachers in the comfort of your browser with video lessons and fun coding challenges and projects.