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开发者_JAVA技巧)+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
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}
@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
}
精彩评论