Re: [R] big big problem

From: Joris Meys <jorismeys_at_gmail.com>
Date: Thu, 17 Jun 2010 16:53:57 +0200

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
______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Thu 17 Jun 2010 - 15:37:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 17 Jun 2010 - 15:40:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive