s-news
[Top] [All Lists]

Re: match

To: Manoel Pacheco <mpacheco@glec.com>
Subject: Re: match
From: Sundar Dorai-Raj <sundar.dorai-raj@pdf.com>
Date: Tue, 27 Mar 2007 07:30:11 -0700
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <001c01c77081$7dd74320$0401a8c0@Manolo>
Organization: PDF Solutions, Inc.
References: <001c01c77081$7dd74320$0401a8c0@Manolo>
User-agent: Thunderbird 1.5.0.10 (Windows/20070221)


Manoel Pacheco said the following on 3/27/2007 8:06 AM:
I have a list of integers,

dat <- c(12, 1, 7, 10, 1, 10, 8, 5, 14, 7, 1, 1, 1, 76, 15, 78)

I can easily exclude ones

n <- dat[dat > 1]

to use the vector n in a function.  The problem I am facing is to match the
function output to the original sequence of values in my list list. I tried

match(n, dat, nomatch = 0)

but the output is all zeroes. Perhaps I can use a vector of the positions
where dat=1.  I would appreciate help to solve this simple problem.

    Thanks,
                    Manolo

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


You get "all zeros"? That's not what I get in S-PLUS 6.2 for Windows:

> dat <- c(12, 1, 7, 10, 1, 10, 8, 5, 14, 7, 1, 1, 1, 76, 15, 78)
> n <- dat[dat > 1]
> match(n, dat, nomatch=0)
 [1]  1  3  4  4  7  8  9  3 14 15 16

But perhaps you really want ?which

> which(dat > 1)
[1]  1  3  4  6  7  8  9 10 14 15 16

It's a bit unclear what you're expecting.

HTH,

--sundar

<Prev in Thread] Current Thread [Next in Thread>