[R] Indexing issue
Neuro LeSuperHéros
neuro3000 at hotmail.com
Tue Aug 1 22:38:14 CEST 2006
Hi,
Try this:
bIm <-array(rep(TRUE,5),c(5,1,1))
bIm[,,1]
#[1] TRUE TRUE TRUE TRUE TRUE
bIm[,,1,drop=FALSE]
, , 1
[,1]
[1,] TRUE
[2,] TRUE
[3,] TRUE
[4,] TRUE
[5,] TRUE
See ?'[' for details on drop
drop: For matrices and arrays. If 'TRUE' the result is coerced to
the lowest possible dimension
>From: "Swidan, Firas" <swidanf at janelia.hhmi.org>
>To: "r-help at stat.math.ethz.ch" <r-help at stat.math.ethz.ch>
>Subject: [R] Indexing issue
>Date: Tue, 01 Aug 2006 15:57:01 -0400
>
>Hi,
>
>R is having the following weird behavior and I am not sure if that is a
>feature or a bug:
>
>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?
>
>Thanks for the help,
>Firas.
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list