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
|