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

From: <ripley_at_stats.ox.ac.uk>
Date: Tue 13 Dec 2005 - 18:10:14 GMT


It is peculiar behaviour on your part, but the developers do not find it at all `funny'.

On Tue, 13 Dec 2005 rasche@molgen.mpg.de wrote:

> 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.

They are, and in your example they work as documented. You have not even told us what you think the bug is.

What happens in clearly stated in the R Language Definition and in all good reference books on R.

> 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.

As it should.

>
> 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]

-- 
Brian D. Ripley,                  ripley@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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

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

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