If I have:
vector <-[1,2,3]
how do I make a vector of equal length thats:
sums <- [1, 3, 6]
I am currently using a for loop:
sums <- c()
for (i in 1:length(vector){
s <- sum(vector[1:i])
sums <- c(sums, c(s))
}
but I am wondering if there is a better alternative.
>Solution :
vec <- 1:10
cumsum(vec)
# [1] 1 3 6 10 15 21 28 36 45 55