R timeseries data

WHAT IS TIME SERIES DATA
Any data which is aligned with time is time series data. For example sales data of 12 months of year is time series data.
Time  Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec

Data  45   67  89    34   12    56  78  89   91   92   68   72
TIME SERIES DATA CREATION
R has a special data structure for storing the time series data. It is created by ts() function.
ts(data, start , end , frequency)
data : data is passed in the form of vector
start : start of time series data
end   : end of time series data (optional)
frequency : Decide the time difference between two readings.
                  : 1 for yearly data i.e 1 observation will be allocated to entire year.
                  : 2 for bimonthly data i.e 2 observation will be allocated to entire year.
                  : 4 for quarterly data i.e 4 observations will be allocated to entire year
                  : 12 for monthly data i.e 12 observations will be allocated to entire year
                  : 52 for weekly data i.e 52 observations will be allocated to entire year
                 : 24 for 15 day data
                 : 365 for daily data
EXAMPLES
1) ts(1:10,start=2000, frequency=1) ## yearly data
Time Series:
Start = 2000
End = 2009
Frequency = 1
 [1]  1  2  3  4  5  6  7  8  9 10

2) ts(1:12,start=2000, frequency=4) ## quarterly data
Qtr1 Qtr2 Qtr3 Qtr4
2000    1    2    3    4
2001    5    6    7    8
2002    9   10   11   12

3) ts(1:12,start=2000, frequency=12 ) ## monthly data
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2000   1   2   3   4   5   6   7   8   9  10  11  12

4) ts(1:24,start=2000, frequency=24) ## fortnight data
Time Series:
Start = c(2000, 1)
End = c(2000, 24)
Frequency = 24
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

5) ts(1:52,start=2000, frequency=52) ## weekly data
Time Series:
Start = c(2000, 1)
End = c(2000, 52)
Frequency = 52
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
[38] 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52




No comments:

Post a Comment

Translate

Monte Carlo Simulation with R

Stochastic Modeling A stochastic model is a tool for modeling data where uncertainty is present with the input. When input has cert...