Bob
Bob

Reputation: 27

Iteration over for loop in r

I am programming R and am confronted with the following syntax errorÖ

Here is the code:

for (i in (1:7)) {for (index in seq(i,56,8)) {values[[length(values)+1]] <- c(ADDLINEORDER[index]) } time_series_values[[length(time_series_value)+1]] <- values}

Error: unexpected symbol in "for (i in (1:7)) {for (index in seq(i,56,8)) {values[[length(values)+1]] <- c(ADDLINEORDER[index]) }  time_series_values"

what I want is: lets say that there is a vector (1,5,6,7,3,9) as input

As I result I want to have it like ((1,6,3),(5,7,9))

1 5 are the starting points, I want it to be iterated by 2 so (1, 6, 9) are together in one list.

Thanks

Upvotes: 0

Views: 11444

Answers (2)

Ari B. Friedman
Ari B. Friedman

Reputation: 72779

@Spacedman has found the problem. Formatting properly also fixes it:

for ( i in (1:7) ) {
  for ( index in seq(i, 56, 8) ) {
    values[[ length(values) + 1 ]] <- c( ADDLINEORDER[index] ) 
  }
  time_series_values[[ length(time_series_value) + 1 ]] <- values
}

Upvotes: 0

Spacedman
Spacedman

Reputation: 94317

Missing semicolon. You pasted this into one line from something that was more than one line?

for (i in (1:7)) {for (index in seq(i,56,8)) {values[[length(values)+1]] <- c(ADDLINEORDER[index]) }; time_series_values[[length(time_series_value)+1]] <- values}

Upvotes: 4

Related Questions