Skip to content
Prev 170081 / 398506 Next

Question about apply()

Dear Peter,

I tried with the comma already, it did not work.
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 67.10938  1696.4   447.0   16.96
2000-01-10 66.87500  1710.9   446.8   17.41
2000-01-11 66.09375  1690.2   448.5   18.51
2000-01-12 65.92188  1677.9   447.8   19.02
2000-01-13 66.54688  1694.4   449.2   19.43
2000-01-14 66.14062  1713.9   449.0   20.76
2000-01-17 66.14062  1713.9   449.0   20.76
2000-01-18 65.65625  1705.4   453.7   21.59
2000-01-19 65.87500  1708.4   454.4   22.28
2000-01-20 65.59375  1692.9   453.4   22.40
2000-01-21 65.51562  1689.6   453.8   22.63
2000-01-24 66.09375  1647.7   452.2   22.26
2000-01-25 66.01562  1654.5   450.7   22.71
2000-01-26 66.14062  1651.3   450.6   22.27
2000-01-27 66.10938  1645.7   451.4   21.75
2000-01-28 66.42188  1602.4   447.5   21.65
+
+ a <- embed(x[,z, drop=FALSE], 2)[,1]/embed(x[,z, drop=FALSE], 2)[,2] - 1
+
+ return(a)
+ }
Error in x[, z, drop = FALSE] : incorrect number of dimensions


Nothing was wrong with your suggestion, except that I did not come up
with it. :-)
I've been using a lot of embed and apply(, 1, FUNC) functions lately
and out of inertia I tried the same.

I specify a new variable (with suffix ."ret") within merge() function.

Kind Regards,
Sergey
On Wed, Feb 11, 2009 at 13:47, Peter Dalgaard <P.Dalgaard at biostat.ku.dk> wrote: