To find the slope of a time series data set in R, you can use linear regression. Here's an example using a simple data set:
main.r238 chars13 lines
In this example, we first create a simple time series data set using the seq
function to create a sequence of numbers and the c
function to create a vector of data. We then run a linear regression using the lm
function, where the ~
symbol indicates the dependent variable (data
) is modeled as a function of the independent variable (time
). We extract the slope coefficient from the resulting model using the coef
function and take the second element, which corresponds to the slope. Finally, we print the slope using the print
function.
gistlibby LogSnag