From ccberry at ucsd.edu  Thu Jan  4 22:09:11 2018
From: ccberry at ucsd.edu (Berry, Charles)
Date: Thu, 4 Jan 2018 21:09:11 +0000
Subject: [Rd] silent recycling in logical indexing
In-Reply-To: <6ba8e484-bc14-bcbb-1d8a-4871909e87f2@gmail.com>
References: <6ba8e484-bc14-bcbb-1d8a-4871909e87f2@gmail.com>
Message-ID: <25B0F325-FD8D-4A43-B711-2329E4847AE9@ucsd.edu>



> On Jan 4, 2018, at 11:56 AM, Ben Bolker <bbolker at gmail.com> wrote:
> 
> 
>  Sorry if this has been covered here somewhere in the past, but ...
> 
>  Does anyone know why logical vectors are *silently* recycled, even
> when they are incommensurate lengths, when doing logical indexing? 

It is convenient to use a single `TRUE' in programmatic manipulation of subscripts in the same manner as using an empty subscript interactively:

> mat<-diag(1:3)
> expr1 <- quote(mat[])
> expr1[[3]] <- TRUE
> expr1[[4]] <- 2
> eval(expr1)
[1] 0 2 0
> mat[,2]
[1] 0 2 0

HTH,

Chuck


[Rd] silent recycling in logical indexing
Berry, Charles