Skip to content

Instantly share code, notes, and snippets.

@guobl
Created December 15, 2012 04:43
Show Gist options
  • Save guobl/4291373 to your computer and use it in GitHub Desktop.
Save guobl/4291373 to your computer and use it in GitHub Desktop.
R Basic Functions
# This example code is to understand the usage of abline function.
library(TSA)
data(rwalk)
model1 = lm(rwalk ~ time(rwalk))
win.graph(width=4.875,height=2.5,pointsize=8)
plot(rwalk,type="o",ylab="y")
abline(model1) # add the fitted least square line from model1
# The graph is omitted here.
# This example code is to unstand the usage of season function.
library(TSA)
data(tempdub) # tempdub is monthly temperature data in package TSA.
month. =season(tempdub) # period added to improve table display
# season function is to extract the season info from a equally spaced time series and create a vector of the season info.
# for example for monthly data, the function outputs a vector containing the months of the data; here, it does.
# the value of season function is an invisible vector containing the seasons of the data.
model2 = lm(tempdub~month.-1) # -1 removes the intercept term
summary(model2)
# This example code is to understand the usage of time function.
labrary(TSA)
data(rwalk) # rwalk is a time series data file in TSA package.
time(rwalk) # time creates the vector of times at which a time series was sampled.
# Time Series:
# Start = 1
# End = 60
# Frequency = 1
# [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] 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment