Problem with [,,,1]

#1
Hi everybody,
I have some problems with this operator []
I have this code:
for (file in files) {
+ img <- f.read.analyze.volume(file)[,,,1]
+ mask3D <- mask3D*(!is.na(img))
+ }
Error in mask3D * (!is.na(img)) : non-conformable arrays
> dim(!is.na(img))
[1] 64 64 18
> for (file in files) {
+ img <- f.read.analyze.volume(file)
+ mask3D <- mask3D*(!is.na(img))
+ }
Error in mask3D * (!is.na(img)) : non-conformable arrays
> dim(!is.na(img))
1] 64 64 19 1

The mask has dimension 64 64 19, what I need to do for having my img of the same dimensions?
 

JesperHP

TS Contributor
#2
It looks weird you need to make a reproducible example because the above behavior is not standard as shown by

Code:
A=array(NA,dim=c(12,12,13,1))
dim(A[,,,1])
so I'm thinking something else is going on in code not shown which may originate in the loop structure which implies reference to several files not necessarily resulting in matching dimensions in all cases