Dear list,
I'll try to be more clear in explaining my problem. I have a data frame like 
this called X:



                        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'm trying to build the time series of the variables (EC01,EC02) by applying 
the following formulas in a recursive way(by starting from value2 at time 
2007). The formulas needed to get the time series are

series(2006)=value2(2007)-value1(2007)

series(2005)=value2(2006)-value1(2006)
In terms of number I would have for example for variable EC01:
series(2006)=5-4=1
series(2005)=1-2=-1
 In addition, this calculations should be down grouping by variable e 
cluster.So the result should be
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
I applied the following formula which gives what I want but not at all:
series=ddply(X,.(variable,CLUSTER),transform,series=rev(value2-cumsum(rev(value1[-1]))))))
The first problems is that I get the following warning message:
longer object length is not a multiple of shorter object length
Secondly If I try to add new years(My aim was to do a check in order to see if 
this procedure works for all type of data frame)
R does the right calculations but the order of the results referred to the 
variable called series is not right.



Thanks for your attention!!!

















        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to