[R] How to index the occasions in a vector repeatedly under condition 1? if not, it will give a new index.

Lijun Zhao ||jun@zh@o @end|ng |rom @de|@|de@edu@@u
Mon Feb 24 01:35:09 CET 2020


Hi Peter,
Thank you so much.

Kind regards,

Lijun

-----Original Message-----
From: peter dalgaard <pdalgd using gmail.com>
Sent: Friday, 21 February 2020 8:16 PM
To: Lijun Zhao <lijun.zhao using adelaide.edu.au>
Cc: William Dunlap <wdunlap using tibco.com>; r-help using r-project.org
Subject: Re: [R] How to index the occasions in a vector repeatedly under condition 1? if not, it will give a new index.

It has isTRUE, but that is not vectorized, and in fact explicitly tests length==1, so

> isTRUE(c(TRUE,FALSE,NA))
[1] FALSE
> isTRUE(c(TRUE,TRUE, TRUE)) # I thought I thaw a puddycat... ;-)
 [1] FALSE
> Vectorize(isTRUE)(c(TRUE,FALSE,NA))
[1]  TRUE FALSE FALSE

(The latter would be silly as an implementation of is_true, of course.)

-pd

> On 20 Feb 2020, at 04:20 , Lijun Zhao <lijun.zhao using adelaide.edu.au> wrote:
>
>
> Some packages have the equivalent of that is_true function, which maps FALSE and NA to FALSE and TRUE to TRUE.  I don't think core R contains such a function.

--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk  Priv: PDalgd using gmail.com



More information about the R-help mailing list