Differences in the start and end Options of the ts Function and the window Function in R
Description
In R, you often use the ts()
and window()
functions when dealing with time series data. ts()
is used to create time series data that R can accept, and window()
is used to extract a portion of the time series data.
Both functions have options for start and end, and their differences are as follows.
ts()
This is an option for giving indices.
start
: Assigns an index to the first element of the data to be made into time series data.end
: Determines up to which element to read. It should not be less than the starting index.
window()
This is an option for following indices.
start
: Determines from which element of the time series data to start reading.end
: Determines up to which element of the time series data to read.
Why is the function name window()
?
The reason for naming the function window()
is because, as shown above, it creates a ‘window’ to view only a portion of the entire data. This expression is popular in many fields, not just in time series analysis.
Code
set.seed(150421)
x<-rnorm(30)
y<-ts(x,start=20,end=40); y
window(y,start=30)
win.graph(4,4); plot(y,main="왜 하필 윈도우인가?")