Confused student here, please help - #Error: object 'x' not found

I don't know what I'm doing wrong:

s=disdata$Close.Last
for(t in 1:length(s)) {
x[t]<-log(s[t]/s[t+1])
}
Error: object 'x' not found

Thanks in advance.

You have not defined x. Try

x <- vector(mode = "numeric", length = length(s))

You should also consider what will happen in your loop when t = length(s) in the last iteration.

Thanks! Silly of me really.

And thanks for the suggestion about when t=length(s).

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.