[R] Indexing issue

Thomas Lumley tlumley at u.washington.edu
Tue Aug 1 22:13:23 CEST 2006


On Tue, 1 Aug 2006, Swidan, Firas wrote:
> Hi,
>
> R is having the following weird behavior and I am not sure if that is a
> feature or a bug:

It's a feature. And a very old FAQ (#7.5)


> I am working on the following "3D" array:
>
>> bIm
> , , 1
>
>     [,1]
> [1,] TRUE
> [2,] TRUE
> [3,] TRUE
> [4,] TRUE
> [5,] TRUE
>
>> class(bIm)
> [1] "array"
>> dim(bIm)
> [1] 5 1 1
>
> When I try to get the first 2D subarray, the whole thing folds into a
> vector:
>
>> bIm[,,1]
> [1] TRUE TRUE TRUE TRUE TRUE
>
> This causes a lot of trouble in the R code as one would have expected to get
> a 2D array but ends up with this "logical" vector.
>
> Is this the way it was meant to be? Does not this behavior bother anyone
> else besides me?

Yes, it is the way it was meant to be. It has bothered other people, but 
the alternatives are probably worse.

 	-thomas



More information about the R-help mailing list