Vector de sumas acumulativas en R
Estoy tratando de obtener un vector de sumas acumulativas, es decir, tengo:
# 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])
}
La última línea de código es el problema, quiero que 'I' sea un vector tal que I [1] = F [1], I [n] = F [1] + F [2] + ..... + F [n]. La función cumsum no funciona para esto por alguna razón. ¿Qué hay de malo en intentar hacerlo así?