0

I have a time series data set like below:

age time    income
16 to 24    2004 q1 400
16 to 24    2004 q2 500
…   …   
65 and over 2014 q3 800

it has different 60 quarters of income data for each age group.as income data is seasonal. i am trying to apply decomposition function to filter out trends.what i have did so far is below. but R consistently throw errors (error message:undefined columns selected) at me. any idea how to go about it?

  fun =function(x){
     ts = ts(x,frequency=4,start=c(2004,1))
     ts.d =decompose(ts,type='additive')
     as.vector(ts.d$trend)
}

  trend.dt = ddply(my.dat,.(age),transform,trend=fun(income))

expected result is (NA is because, after decomposition, the first and last ob will not have value,but the rest should have)

age        time  income  trend     
16 to 24    2004 q1 400  NA 
16 to 24    2004 q2 500  489
…   …
65 and over 2014 q3 800  760
65 and over 2014 q3 810  NA 
Lawrence
  • 277
  • 1
  • 3
  • 13
  • 1
    Please take the time to include a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Include sample data that can easily be imported or copy/pasted into R (yours cannot) and also include the desired results. If you get errors, list the exact errors you receive. – MrFlick Jan 15 '15 at 19:45
  • Perhaps you're missing a comma somewhere, see https://stackoverflow.com/questions/19205806/r-undefined-columns-selected-in-subsetting-my-data-frame – talat Jan 15 '15 at 20:22

0 Answers0