Does anyone know which function (if any) will return the index of the true locations in a Boolean vector? For instance: A=c(1,3,5,7,4); B=c(2,4,77,3,3); X=A<B; So X is:> X[1] TRUE TRUE TRUE FALSE FALSE I'd like to know if there is a function that will tell me the locations of where the TRUE values are? for instance a vector that will list that the locations are at 1, 2, 3. This function is sometimes called loc() in other languages. Thanks, Jennifer [[alternative HTML version deleted]]
?which> which(X)[1] 1 2 3 Max -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Barb, Jennifer (NIH/CIT) [E] Sent: Tuesday, November 20, 2007 3:07 PM To: r-help at stat.math.ethz.ch Subject: [R] Loc function in R?? Does anyone know which function (if any) will return the index of the true locations in a Boolean vector? For instance: A=c(1,3,5,7,4); B=c(2,4,77,3,3); X=A<B; So X is:> X[1] TRUE TRUE TRUE FALSE FALSE I'd like to know if there is a function that will tell me the locations of where the TRUE values are? for instance a vector that will list that the locations are at 1, 2, 3. This function is sometimes called loc() in other languages. Thanks, Jennifer [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
?which On 21/11/2007, at 9:06 AM, Barb, Jennifer (NIH/CIT) [E] wrote:> Does anyone know which function (if any) will return the index of the > true locations in a Boolean vector? > > > > For instance: > > A=c(1,3,5,7,4); > > B=c(2,4,77,3,3); > > X=A<B; > > > > So X is: > >> X > > [1] TRUE TRUE TRUE FALSE FALSE > > > > I'd like to know if there is a function that will tell me the > locations > of where the TRUE values are? for instance a vector that will list > that > the locations are at 1, 2, 3. This function is sometimes called loc() > in other languages.###################################################################### Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
try: which(X) Best, Dimitris ---- Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm Quoting "Barb, Jennifer (NIH/CIT) [E]" <barbj at mail.nih.gov>:> Does anyone know which function (if any) will return the index of the > true locations in a Boolean vector? > > > > For instance: > > A=c(1,3,5,7,4); > > B=c(2,4,77,3,3); > > X=A<B; > > > > So X is: > >> X > > [1] TRUE TRUE TRUE FALSE FALSE > > > > I'd like to know if there is a function that will tell me the locations > of where the TRUE values are? for instance a vector that will list that > the locations are at 1, 2, 3. This function is sometimes called loc() > in other languages. > > > > Thanks, > > Jennifer > > > > > > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
?which On Tue, 20 Nov 2007, Barb, Jennifer (NIH/CIT) [E] wrote:> Does anyone know which function (if any) will return the index of the > true locations in a Boolean vector? > > > > For instance: > > A=c(1,3,5,7,4); > > B=c(2,4,77,3,3); > > X=A<B; > > > > So X is: > >> X > > [1] TRUE TRUE TRUE FALSE FALSE > > > > I'd like to know if there is a function that will tell me the locations > of where the TRUE values are? for instance a vector that will list that > the locations are at 1, 2, 3. This function is sometimes called loc() > in other languages. > > > > Thanks, > > Jennifer > > > > > > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >_________________________________________________________________ David Scott Department of Statistics, Tamaki Campus The University of Auckland, PB 92019 Auckland 1142, NEW ZEALAND Phone: +64 9 373 7599 ext 86830 Fax: +64 9 373 7000 Email: d.scott at auckland.ac.nz Graduate Officer, Department of Statistics Director of Consulting, Department of Statistics
which(A < B) On Nov 20, 2007, at 3:06 PM, Barb, Jennifer (NIH/CIT) [E] wrote:> Does anyone know which function (if any) will return the index of the > true locations in a Boolean vector? > > > > For instance: > > A=c(1,3,5,7,4); > > B=c(2,4,77,3,3); > > X=A<B; > > > > So X is: > >> X > > [1] TRUE TRUE TRUE FALSE FALSE > > > > I'd like to know if there is a function that will tell me the locations > of where the TRUE values are? for instance a vector that will list > that > the locations are at 1, 2, 3. This function is sometimes called loc() > in other languages. > > > > Thanks, > > Jennifer > > > > > > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.