Vetor de somas acumuladas em R
Estou tentando obter um vetor de somas cumulativas, ou seja, tenho:
# 500 Samples from the U(0,1) Distribution
U<-runif(500,0,1)
# Empty Vector of length 500
F<-rep(0,500)
# Fill the vector with f(U(k))
for ( i in 1:500 ){
F[i] <- sqrt(1-U[i]^2)
}
# Another Empty Vector of length 500
I<-rep(0,500)
# Fill the second empty vector with the sums of F
for ( i in 1:500 ){
I[i]<-cumsum(F[1]:F[i])
}
A última linha do código é o problema, eu quero que 'I' seja um vetor tal que I [1] = F [1], I [n] = F [1] + F [2] + ..... + F [n]. A função cumsum não funciona por isso por algum motivo. O que há de errado em tentar fazer assim?