Time series in R
r, time-series
Solution
Read the data into R using `x <- read.csv(filename)`. Make sure the dates come in as character class and weight as numeric. Then use the following:
require(zoo)
require(forecast) # Needed for the ses function
x$date <- as.Date(x$date,"%m/%d/%Y") # Guessing you are using the US date format
x$weight <- zoo(x$weight,x$date) # Allows for irregular dates
plot(x$weight, xlab="Date", ylab="Weight") # Produce time plot
ewma <- as.vector(fitted(ses(ts(x$weight)))) # Compute ewma with parameter selected using MLE
lines(zoo(ewma,x$date),col="red") # Add ewma line to plot
Problem
I am tracking my body weight in a spread sheet but I want to improve the experience by using R. I was trying to find some information about time series analysis in R but I was not successful. The data I have here is in the following format: ``` date -> weight -> body-fat-percentage -> water-percentage ``` e.g. ``` 10/08/09 -> 84.30 -> 18.20 -> 55.3 ``` What I want to do `plot` weight and exponential moving average against time How can I achieve that?