Message-ID: <5681DFB7-600A-4BE2-BAEE-59C778AE8755@gmail.com>
Date: 2009-07-21T18:34:54Z
From: Steve Lianoglou
Subject: Searching for specific values in a matrix
In-Reply-To: <60b3892e0907211047i67f3a68m5e5c77485d7ed2@mail.gmail.com>
On Jul 21, 2009, at 1:47 PM, Mehdi Khan wrote:
> Hello all,
>
> I have a seemingly simple question which I have searched for an
> answer for
> for a few hours without luck. I have a matrix of both values and
> characters
> with thousands of rows. I would like to run a search of this matrix
> for
> certain values and would like the search to retrieve the entire
> row. How
> would I accomplish this?
Oh, values! Woops
Like so?
df <- data.frame(nums=1:10, words=c("Abelonian",
"abeltree",
"Abencerrages",
"abenteric",
"abepithymia",
"Aberdeen",
"aberdevine",
"Aberdonian",
"Aberia",
"aberrance"))
evens <- df$nums %% 2 == 0
df[evens,]
You can build such an indexing vector (like evens) in a number of
different ways to suite your problem.
-steve
--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact