[R] big big problem

Joris Meys jorismeys at gmail.com
Thu Jun 17 16:53:57 CEST 2010


It seems to me you're not aware of what that code is doing. You can
easily add the 5 by :

ddply(X,.(variable,CLUSTER),transform,series=c(rev(value2[-1]-cumsum(rev(value1[-1]))),rev(value2)[1]))

Try to figure out what the code is doing exactly for next time, you'll
definitely benefit from it.
Cheers
Joris


On Thu, Jun 17, 2010 at 4:29 PM, n.vialma at libero.it <n.vialma at libero.it> wrote:
> Well English is not my mother tongue too and for me its very difficult to
> explain the procedure also because the procedure is not easy.
> Anyway, with the command that you gave me I solved the problem, by putting 0
> this code works for all type of data frame
> series=ddply(X,.(variable,CLUSTER),transform,series=rev(value2-c(0,cumsum(rev(value1[-1]))))).
> Concerning the formulas I provide for the construction of the time series,
> they are right but  another way to get the same results is to make
> series=rev(value2-cumsum(rev(value1[-1]))))),so by using the cumsum
> function.
> To be honest my data are different from what I put in my example and I didnt
> check  If the code would have worked for the data frame given as example.
> I have a question for you, suppose that the result that you get with this
> formula
>
> series=ddply(X,.(variable,CLUSTER),transform,series=rev(value2-c(0,cumsum(rev(value1[-1])))))
> are right. What I get (in my real data set) is not this:
>     --
>
> TABLE1
>
>                 CLUSTER        YEAR      variable        series
>
>                 M1                     2005         EC01
> -1
>
>                 M1                     2006         EC01             1
>
>                 M1                     2007         EC01              5
>
>                 M2                     2005          EC01             -6
>
>                 M2                     2006          EC01             -1
>
>                 M2                     2007          EC01              7
>
>                 M1                     2005          EC02              4
>
>                 M1                     2006          EC02               7
>
>                 M1                    2007            EC02              8
>
>                 M2                    2005            EC02             -5
>
>                 M2                    2006            EC02            4
>
>                 M2                    2007            EC02             10
>
>
> but this: TABLE2
>
>              CLUSTER        YEAR      variable        series
>
>                 M1                     2005         EC01
> -1
>
>                 M1                     2006         EC01             1
>
>                 M1                     2007         EC01              NA
>
>                 M2                     2005          EC01             -6
>
>                 M2                     2006          EC01             -1
>
>                 M2                     2007          EC01              NA
>
>                 M1                     2005          EC02              4
>
>                 M1                     2006          EC02               7
>
>                 M1                    2007            EC02              NA
>
>                 M2                    2005            EC02             -5
>
>                 M2                    2006            EC02            4
>
>                 M2                    2007            EC02             NA
>
> So I dont have in my final data frame the value of the series at time 2007
> which should be  what I called value1 at time 2007 in the "original data
> frame"  (as shown in table 1) which is this one (that I gave as example):
>
> CLUSTER        YEAR      variable         value1          value2
>
> M1                     2005         EC01           NA              NA
>
>
> M1                     2006         EC01            2                5
>
> M1                     2007         EC01            4                5
>
> M2                     2005          EC01          NA              NA
>
> M2                     2006          EC01           5                7
>
>
> M2                     2007          EC01           8                 7
>
> M1                     2005          EC02           NA               NA
>
> M1                     2006          EC02            3                 8
>
> M1                    2007            EC02           1                 8
>
> M2                    2005            EC02           NA               NA
>
> M2                    2006            EC02           9                 10
>
> M2                    2007            EC02            6                 10
>
>
>
> I put 1 instead of 0 in the code
>
> series=ddply(X,.(variable,CLUSTER),transform,series=rev(value2-c(0,cumsum(rev(value1[-1])))))
>
> but I get Table 2 instead of table 1.
>
> Thanks a lot for your attention and sorry for my english and my scary
> example....
>



-- 
Joris Meys
Statistical consultant

Ghent University
Faculty of Bioscience Engineering
Department of Applied mathematics, biometrics and process control

tel : +32 9 264 59 87
Joris.Meys at Ugent.be
-------------------------------
Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php


More information about the R-help mailing list