[R] Question about apply()

2009-02-11 Thread Sergey Goriatchev
Hello, everyone! Assume you have this data: data - structure(c(66.609375, 67.09375, 66.40625, 66.734375, 67.109375, 66.875, 66.09375, 65.921875, 66.546875, 66.140625, 66.140625, 65.65625, 65.875, 65.59375, 65.515625, 66.09375, 66.015625, 66.140625, 66.109375, 66.421875, 1702.7, 1647.7, 1649.4,

Re: [R] Question about apply()

2009-02-11 Thread Gabor Grothendieck
See ?diff.zoo dif - diff(data, arithmetic = FALSE) - 1 cbind(data, dif) On Wed, Feb 11, 2009 at 6:21 AM, Sergey Goriatchev serg...@gmail.com wrote: Hello, everyone! Assume you have this data: data - structure(c(66.609375, 67.09375, 66.40625, 66.734375, 67.109375, 66.875, 66.09375,

Re: [R] Question about apply()

2009-02-11 Thread Peter Dalgaard
Sergey Goriatchev wrote: Hello, everyone! Assume you have this data: data - structure(c(66.609375, 67.09375, 66.40625, 66.734375, 67.109375, 66.875, 66.09375, 65.921875, 66.546875, 66.140625, 66.140625, 65.65625, 65.875, 65.59375, 65.515625, 66.09375, 66.015625, 66.140625, 66.109375,

Re: [R] Question about apply()

2009-02-11 Thread Sergey Goriatchev
Dear Gabor, Thank you as always. I will follow your suggestion. But, I still want to know what I do wrong in the above code (with embed(), apply(), and merge() functions). Why do I get that error message and how can I rewrite the code to make it run. Best Regards, Sergey On Wed, Feb 11, 2009 at

Re: [R] Question about apply()

2009-02-11 Thread Sergey Goriatchev
Dear Peter, I tried with the comma already, it did not work. rets TY1.lev SP1.lev GC1.lev CL1.lev 2000-01-03 66.60938 1702.7 453.7 18.34 2000-01-04 67.09375 1647.7 447.8 18.29 2000-01-05 66.40625 1649.4 446.2 17.65 2000-01-06 66.73438 1639.9 446.5 17.52 2000-01-07

Re: [R] Question about apply()

2009-02-11 Thread Peter Dalgaard
Sergey Goriatchev wrote: Dear Peter, I tried with the comma already, it did not work. Ah, yes, sorry. The real issue is that you are trying to index twice, both by apply(.,2,.) and by z=TY1.lev (the former loops over columns and the latter selects one of them). So what func() sees is an

Re: [R] Question about apply()

2009-02-11 Thread Gabor Grothendieck
There is no zoo method for embed. embed is implicit in rollapplly so its not normally needed in zoo and rollapply, lag or diff would normally be used instead. If you did want to use embed then unzoo data first but that will lose the time index so add it back in later: e -

Re: [R] Question about apply()

2009-02-11 Thread Sergey Goriatchev
Understood. Peter, Gabor, thank you for your time and help. Regards, Sergey On Wed, Feb 11, 2009 at 14:24, Gabor Grothendieck ggrothendi...@gmail.com wrote: There is no zoo method for embed. embed is implicit in rollapplly so its not normally needed in zoo and rollapply, lag or diff would