[R] subset question

Sarah Goslee sarah.goslee at gmail.com
Wed Dec 29 23:35:29 CET 2010


Details of *what* didn't work would be helpful, like for example
error messages.

Regardless, I'd do it like this:

subd <- d[, d$gene %in% c("i1","i2","i3"), ]


> d
  gene 1  2  3
1   i1 1  6 11
2   i5 2  7 12
3   i2 3  8 13
4   i3 4  9 14
5   i1 5 10 15

> d[d$gene  %in% c("i1","i2","i3"), ]
  gene 1  2  3
1   i1 1  6 11
3   i2 3  8 13
4   i3 4  9 14
5   i1 5 10 15

Sarah

On Wed, Dec 29, 2010 at 5:29 PM, ANJAN PURKAYASTHA
<anjan.purkayastha at gmail.com> wrote:
> nope, that did not work.
> thanks though.1"
> Anjan
>
> On Wed, Dec 29, 2010 at 5:02 PM, Jonathan Flowers <
> jonathanmflowers at gmail.com> wrote:
>
>> Try subd <- d[, "gene" == c("i1","i2","i3")]
>>
>> On Wed, Dec 29, 2010 at 4:55 PM, ANJAN PURKAYASTHA <
>> anjan.purkayastha at gmail.com> wrote:
>>
>>> Hi,
>>> I'm having a problem with a step that should be pretty simple.
>>> I have a dataframe, d,  with column names : gene s1 s2 s3. The column
>>> "gene"
>>> stores an Id; the rest of the columns store intensity data.
>>> I would like to extract the rows for gene Ids i1, i2, i3 ( I know a priori
>>> that those rows exist).
>>> So I do this:
>>> subset(d, gene %in% c(i1, i2, i3)).
>>> This does not give me the required data.
>>> Any ideas where I am going wrong?
>>> TIA,
>>> Anjan
>>>

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list