# [R] drop=F in [

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Jul 25 16:19:45 CEST 2001

```On Wed, 25 Jul 2001, Agustin Lobo wrote:

>
> Within a program, I subset a data matrix. Sometimes
> it comes to remain one single row (indivual) out of the
> subseting. The fact that the single row becomes
> a vector with dim(x)=NULL instead of a matrix
> with dim(x)=c(1,n), is inconvenient for further operations
> in the program.
>
> I thought that drop=F would solve this problem but...

Be careful.  It's FALSE not F.  Indeed it solves the problem, but only if
used as specified on the help page....

> lets a be:
>
> > a
>           [,1]     [,2]      [,3]
> [1,] 0.3249816 1.184596 1.0408749
> [2,] 1.4722996 1.408512 0.3768964
> [3,] 1.2737683 1.811588 1.9108336
> [4,] 1.8235127 1.260909 1.5995097
>
> Then
>
> > a[a[,1]<1,]
> [1] 0.3249816 1.1845962 1.0408749
>
> > dim(a[a[,1]<1,])
> NUL
>
> But,
>
> > a[a[,1]<1,drop=F]
> [1] 0.3249816 1.1845962 1.0408749

> > dim(a[a[,1]<1,drop=F])
> NULL
>
> No way to get dim(a[a[,1]<1,]) equal to c(1,3) ?

No way, *but* if you use this correctly you will get what you want.

Read ?Extract carefully.  You have assumed that

x[i, j, ... , drop=TRUE]

can be contracted, but it does not say so (nor can it in S).

Try

> a[a[,1]<1,, drop=FALSE]
[,1]     [,2]     [,3]
[1,] 0.3249816 1.184596 1.040875

--
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```