Time series in R
Translations
Englishالعربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
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 succesful.
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?
This question and answers originated from www.stackoverflow.com
Question by Christian Stade-Schuldt (10/10/2009 7:57:34 PM)
Answer |
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
Answer by Rob Hyndman
Find More Answers
Related Topics r time-series