Time series in R

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 (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

Find More Answers
Related Topics  r  time-series
Related Questions
  • time series in R

    here is my question: i have these data summary(data) Date 1990/01: 1 1990/02: 1 1990/03: 1 1990/04: 1 1990/05: 1 1990/06: 1 (…
  • time series barplot in R

    i have a time series data like this: x <- structure(list(date = structure(c(1264572000, 1266202800, 1277362800, 1277456400, 1277859600, 1278032400, 1260370800, 1260892800, 1262624400, 126270…
  • plotting time series in R

    I am working with data, 1st two columns are dates, 3rd column is symbol, and 4th and 5th columns are prices. So, I created a subset of the data as follows: test.sub<-subset(test,V3=="GOOG",sel…
  • Monthly Time series in R

    I have a data frame of 2M unix timestamps and I want to make a monthly histogram of that. Any suggestions? thanks
  • Multivariate time series modelling in R

    I want do fit some sort of multi-variate time series model using R. Here is a sample of my data: u cci bci cpi gdp dum1 dum2 dum3 dx 16.50 14.00 53.00 45.70 80.63 0 0 1 6.…
  • recoding time series data in r

    I am trying to recoding a existing data with a overtime structure. My dataset looks like this: dput(z) structure(list(democracy = c(0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0…
  • Time Series in R with ggplot2

    I'm a ggplot2 newbie and have a rather simple question regarding time-series plots. I have a data set in which the data is structured as follows. Area 1998 1999 2000 2001 2002 2003 2004 200…
  • Storing complex time-series in R

    I have a dataframe with several columns: state county year Then x, y, and z, where x, y, and z are observations unique to the triplet listed above. I am looking for a sane way to store…
  • Generating a lagged time series cross sectional variable in R

    I am a new R user. I have a time series cross sectional dataset and, although I have found ways to lag time series data in R, I have not found a way to create lagged time-series cross sectional vari…
  • R ggplot2 plot several time series in a plot

    After succeeding (with your help) in plotting meteo variables in single (one variable) graphs I'm trying to produce a panel with time series of the different variables in my data in a single panel, …