So I have a 252 rows of data in column 4, and I would like to find the difference between two consecutive rows throughout the entire column
My current code is:
appleClose<-NULL
for (i in 1:Apple[1]){
appleClose[i] <- AA[i,4]
}
appleClose[]
I tried, and failed, with:
appleClose<-NULL
for (i in 1:Apple[1]){
appleClose[i] <- AA[i,4] - AA[i+1,4]
}
appleClose[]
Edit: I am trying to optimize a stock market portfolio in retrospect. AA is the ticker symbol for Apple. I downloaded that information through some R code written earlier in the program. I have not yet checked out the diff function yet. I will do that now.
The error I am receiving is
Error in
[.xts
(AA, i + 1, 4) : subscript out of bounds