课程: R for Data Science: Lunch Break Lessons

免费学习该课程!

今天就开通帐号,24,100 门业界名师课程任您挑!

diff

diff

- [Instructor] Diff is a utility, best used with time series data, but it can be used with any sequential vector information. It returns a lagged and iterated differences between the elements of a vector. Now that's kind of a confusing phrase. So let's use some plots and graphs to show you exactly what's happening when diff operates on a vector. First of all, I've created a vector. We're calling it Vector one, and you can see that it contains a sequence of numbers; two, four, three, six, five, 10, nine, 18. Let's dive right in and find out what diff does with that vector. So I'll type in diff, D-I-F-F. I want to find the diff in Vector one, and I'm going to lag by two. I'll run that, and you can see that what I receive is one, two, two, four, four, eight. Now how these numbers are created is a result of a somewhat complex formula. And I've worked that out for you in the example file. If you're curious, I would…

内容