# [S] Matrix Extraction

Erin Hodgess (hodgess@uhdux2.dt.uh.edu)
Sat, 21 Feb 1998 11:58:45 -0600

Dear Kirthi:

Here is a possible solution for your matrix-extract problem.

I tried something a little bit different that you might enjoy.
I constructed a function called "posrow" that looks for
all positive elements. Then I used the "apply" function.

> x1
[,1] [,2] [,3]
[1,] 0 1 -1
[2,] 2 1 2
[3,] 3 1 7

> posrow
function(x)
{
y <- all(x >= 0)
y
}
> apply(x1,1,FUN=posrow)
[1] F T T

I hope this helps!

Sincerely,
Erin Hodgess
Assistant Professor
Dept. of Computer and Mathematical Sciences
University of Houston -- Downtown
e-mail: hodgess@uhdux2.dt.uh.edu

From: "Kirthi Kalyanam" <KKalyanam@mailer.scu.edu>

Subject: [S] Newbie question: Extracting rows of a matrix with positive
elements

This is a very very basic question. We tried several things and looked up
appropriate.

I want to extract all the rows of a matrix X that have positive elements in
it. For example if X is:

0, 1,-1
2,1,2
3,1,7

then I want to extract only lines 2 and 3.

Thanks for any suggestions. (By the way I am curious as to where in the
programmers manuals issues like this are covered).

--------------------------------------------------------------------------------------
Kirthi Kalyanam, Ph.D. - Asst. Professor & Associate Director
Retail Management Institute & Retail Workbench Research Center
500 El Camino Real, Santa Clara, CA 95053
TEL: 408.554.2705 FAX:
408.554.5056

--------------------------------------------------------------------------------------

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news