[R] creating a vector of sums

Alain Guillet alain.guillet at uclouvain.be
Tue Apr 28 12:19:19 CEST 2009


Look at cumsum()

Alain

Rachel Taylor wrote:
> Hi,
>  
> I am trying to create a function for a goodness-of-fit test for the Pareto Distribution for some loss data that I have.
> So far I have the following:
>  
> function(X=OTOL)
> {
> n <- length(X)-1 #calculated the number of values (extra as 0 included)
> i <- 2:640 #values of i
> j <- 1:639 #values of i-1
> Y <- (n-j+1)*((X[i])-(X[j])) #First part of GoF model
> Y
> }
>  
> Where OTOL is the ordered loss data (decreasing), and Y is a vector of length 639
>  
> What I need to do next is create another vector TY (of the same length) that is the the sum of part of the Y vector.
> So TY[1]=Y[1]
> TY[2]=Y[1]+Y[2]
> TY[3]=Y[1]+Y[2]+Y[3]
> and so on.
>  
> I have tried to do a sum(Y[j]) but it just comes out with a single value.
>  
> Any help is greatly appreciated, thank you.
>  
> Rachel
>
> ______________________________________________
> 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.
>
>   

-- 
Alain Guillet
Statistician and Computer Scientist

SMCS - Institut de statistique - Université catholique de Louvain
Bureau d.126
Voie du Roman Pays, 20
B-1348 Louvain-la-Neuve
Belgium

tel: +32 10 47 30 50




More information about the R-help mailing list