-3

I have a list in R, comprised of time series objects:

X<-list(a, b, c, ..., n)

This list is huge and I would like to:

  1. Create a new object for every object in the list.
  2. 'Push' these objects to the end of the list.
  3. Decompose the first time series objects (a, ..., n) and save these decomposed objects as the new objects newly created in step 1).

Is there a way to do this easily? Am I missing a crucual package?

tiago
  • 22,602
  • 12
  • 72
  • 88
erasmortg
  • 3,246
  • 1
  • 17
  • 34
  • 1
    Is this more complicated than `lapply(X, createNewObjectFunction )` ? – Neal Fultz May 21 '14 at 17:04
  • 1
    Could you perhaps be a bit more specific about what you are trying to do. Perhaps make a [reproducible example or include test data](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – MrFlick May 21 '14 at 18:21

1 Answers1

1

Just to make concrete what (I think) neal was suggesting:

a=cumsum(rnorm(100))
b=cumsum(rnorm(200))
c=cumsum(rnorm(10))
d=cumsum(rnorm(50))

X=list(a=a,b=b,c=c,d=d)

createnewobjfun=function(x) sin(x)

Xnew=c(X,lapply(X, createnewobjfun ) )

Then examine the structure of X and Xnew to see if it conforms to your expectations.

> str(X)
List of 4
 $ a: num [1:100] 1.239 0.363 0.698 1.73 0.935 ...
 $ b: num [1:200] 1.94 2.41 4.18 2.21 3.35 ...
 $ c: num [1:10] 0.491 -0.273 -0.422 1.399 0.362 ...
 $ d: num [1:50] 0.465 1.828 1.595 0.976 -0.476 ...
> 
> str(Xnew)
List of 8
 $ a: num [1:100] 1.239 0.363 0.698 1.73 0.935 ...
 $ b: num [1:200] 1.94 2.41 4.18 2.21 3.35 ...
 $ c: num [1:10] 0.491 -0.273 -0.422 1.399 0.362 ...
 $ d: num [1:50] 0.465 1.828 1.595 0.976 -0.476 ...
 $ a: num [1:100] 0.946 0.355 0.643 0.987 0.804 ...
 $ b: num [1:200] 0.931 0.671 -0.861 0.805 -0.203 ...
 $ c: num [1:10] 0.472 -0.27 -0.41 0.985 0.354 ...
 $ d: num [1:50] 0.449 0.967 1 0.828 -0.458 ...

So there is a problem with the naming, I think that could be remedied in your lapply call

I have no idea what you are describing in step 3.

Seth
  • 4,745
  • 23
  • 27