problem with Loop cycle --> list of NA as results

Good afternoon Guys,
I have a problem with this for cyle

I don't know why it is giving me back a list of NA for all the numbers before the last one.

here's the code,
hope you can help me with this basic issue

thank You

A <- c(1,2,5, 45, 5, 34, 34,23 ,23 ,765)
ten <- vector()

for(i in 0:9)
  ten_ <- A[i:(i+1)]
  tene <- sum(ten_)
  tenemea <- tene / 2
  ten[i] <- tenemea

You need braces round the code you want to include within the loop

See the examples at the bottom of ?'for'

1 Like

thanks a lot @jmcvw that was the solution

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.