Hello, A brief question that I am not able to resolve by my own, but I presume it's easy for you: I've used apply to find the values closer to 0 in each row of a matrix: closer.to.0 <- apply(abs(myarray),MARGIN=1,"min") My question is how could I use which (or another way) to obtain a vector that indicates which columns contains these "closer to 0" values? (I know I can loop, but I mean a faster and elegant way) Thanks and best regards Javier -- Javier Garc?a-Pintado Institute of Earth Sciences Jaume Almera (CSIC) Lluis Sole Sabaris s/n, 08028 Barcelona Phone: +34 934095410 Fax: +34 934110012 e-mail:jgarcia at ija.csic.es
javier garcia-pintado <jgarcia at ija.csic.es> writes:> Hello, > A brief question that I am not able to resolve by my own, but I presume > it's easy for you: > > I've used apply to find the values closer to 0 in each row of a matrix: > > closer.to.0 <- apply(abs(myarray),MARGIN=1,"min") > > My question is how could I use which (or another way) to obtain a vector > that indicates which columns contains these "closer to 0" values? > > (I know I can loop, but I mean a faster and elegant way)Is it which.min that you're looking for? -- 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 at biostat.ku.dk) FAX: (+45) 35327907
javier garcia-pintado wrote:> Hello, > A brief question that I am not able to resolve by my own, but I presume > it's easy for you: > > I've used apply to find the values closer to 0 in each row of a matrix: > > closer.to.0 <- apply(abs(myarray),MARGIN=1,"min") > > My question is how could I use which (or another way) to obtain a vector > that indicates which columns contains these "closer to 0" values??which.min which.closer.to.0 <- apply(abs(myarray), 1, which.min)> (I know I can loop, but I mean a faster and elegant way) > > Thanks and best regards > > Javier > > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at stat.math.ethz.ch 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.-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894