I am in my first steps of coding in R.
I am trying to fill a matrix, which is based on some vectors inside a matrix. This is my matrix:
OPEN NET_CONTRIBUTION RETURN CONTRIBUTION_RETURN SAVING_RETURN CLOSE
[1,] 0 900 0.019 17.1 0 ?
[2,] 917.1 900 -0.006 -5.4 0 ?
[3,] ? 900 0.004 3.6 0 ?
[4,] 903.6 900 0.004 3.6 0 ?
[5,] 903.6 900 0.002 1.8 0 ?
[6,] 901.8 900 0.002 1.8 0 ?
NET_CONTRIBUTION is a vector with a constant number. Return is a vector of random values.
- CONTRIBUTION_RETURN is the calculation of NET_CONTRIBUTION * (1+RETURN).
- SAVING_RETURN should be Open*(1+RETURN)
CLOSE should be OPEN + NET_CONTRIBUTION + CONTRIBUTION_RETURN + SAVING RETURN
OPEN is the CLOSE value for the upper row.
So I tried this code, and it doesn't work.
for (i in 1:444){
Investment[i,5] <- Investment[i,1]*(1+Investment[i,3]) #Saving Return
Investment[i,6] <- Investment[i,1] + Investment[i,2] + Investment[i,4] Investment[i,5] # CLOSE
Investment[i+1,1] <- (Investment[i,6]) # OPEN in the next row
}
I get the following message:
> > for (i in 1:444){
> + Investment[i,5] <- Investment[i,1]*(1+Investment[i,3])
> + Investment[i,6] <- Investment[i,1] + Investment[i,2] + Investment[i,4] Investment[i,5] Error: unexpected symbol in: "
> Investment[i,5] <- Investment[i,1]*(1+Investment[i,3])
> Investment[i,6] <- Investment[i,1] + Investment[i,2] +
> Investment[i,4] Investment"
> > Investment[i+1,1] <- (Investment[i,6])
Maybe I am not aprroaching in the right way this idea. Thank you all for your help, Tom