Re: [Rd] 0/1 vector for indexing leads to funny behaviour (PR#8389)

From: Peter Dalgaard <p.dalgaard_at_biostat.ku.dk>
Date: Tue 13 Dec 2005 - 16:37:36 GMT

rasche@molgen.mpg.de writes:

> Full_Name: Axel Rasche
> Version: 2.2.0
> OS: Linux
> Submission from: (NULL) (141.14.21.81)
>
>
> Dear Debuggers,
>
> This is not a serious problem. Are 0/1 vectors intended to be used as index
> vectors? If yes, there is a bug. If not, it leads just to some funny behaviour
> rather than an error message.
>
> In the appendix is some simple code to reproduce the problem. A logical vector
> as.logic(a) helps by indexing the vector b. The 0/1 vector a just returns the
> first value "a". But as many times as there is a 1 in a.

Yes, that is completely as intended. Zeros in a numerical index vector produce nothing and ones produce the first element. The documentation could arguably be better on this point though.  

> Best regards,
> Axel
>
>
> Appendix:
>
> b = c("a","b","c","d")
> a = c(0,1,1,0)
> b[as.logical(a)]
> b[a]
> a = c(1,0,1,0)
> b[as.logical(a)]
> b[a]
> a = c(0,1,1,1)
> b[as.logical(a)]
> b[a]
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
   O__  ---- Peter Dalgaard             ุster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed Dec 14 05:07:40 2005

This archive was generated by hypermail 2.1.8 : Tue 13 Dec 2005 - 21:21:48 GMT