I think this is very easy but my R kung-fu is weak. I'm trying to create a vector of itself in a cumulative way. This code works but I'd like something much more elegant and automated. I have millions of rows that need to be cumulated.
a <- c(4,4,5,1,9)
a <- a[order(-a[])]
k <- a[1:length(a)]/sum(a)
w <- c(k[1],k[1]+k[2],k[1]+k[2]+k[3],k[1]+k[2]+k[3]+k[4],k[1]+k[2]+k[3]+k[4]+k[5])
w