R seems to treat multidimensional array as one single array. Is there a way to loop through the array and keep the structure in it?
It seems that I couldn't only use for i in 1:length(...) either, I'll need to know the dimension of the array at all time as length just returns the total size. Is c not the correct function to use here? Thanks.
components = array(c( c(1, 0, 0, 0, 0, 0, 0, 0, 0, 0),
c(0, 1, 0, 1, 0, 1, 0 ,1, 0, 1),
c(0, 0, 1, 0, 0, 1, 0 ,0, 1, 0),
c(0, 1, 1, 1, 1, 1, 1, 1, 1, 1)), dim=c(4,10) )
components
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 1 0 0 0 0 0 0 1 1 1
[2,] 0 0 0 1 1 0 1 0 1 1
[3,] 0 0 0 0 0 1 0 0 1 1
[4,] 0 0 1 1 1 0 0 1 1 1
for( component in components ){ print(component) }
[1] 1
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 0
[1] 1
[1] 0
[1] 1
[1] 0
[1] 1
[1] 0
[1] 1
[1] 0
[1] 1
[1] 0
[1] 0
[1] 1
[1] 0
[1] 0
[1] 1
[1] 0
[1] 0
[1] 1
[1] 0
[1] 0
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
> length(components)
[1] 40