[R] Is there a neat R trick for this?

2013-02-12 Thread Robert Latest
Hello all, given two vectors X and Y I'd like to receive a vector Z which contains, for each element of X, the index of the corresponding element in Y (or NA if that element isn't in Y). Example: x - c(4,5,6) y - c(10,1,5,12,4,13,14) z - findIndexIn(x, y) z [1] 5 3 NA 1st element of z is 5,

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Jorge I Velez
Robert, Try match(x, y) HTH, Jorge.- On Tue, Feb 12, 2013 at 9:09 PM, Robert Latest boblat...@gmail.com wrote: Hello all, given two vectors X and Y I'd like to receive a vector Z which contains, for each element of X, the index of the corresponding element in Y (or NA if that element

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Rainer Hurling
Am 12.02.2013 11:09 (UTC+1) schrieb Robert Latest: x - c(4,5,6) y - c(10,1,5,12,4,13,14) Please try #match(x,y) [1] 5 3 NA HTH, Rainer Hurling __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Berend Hasselman
On 12-02-2013, at 11:09, Robert Latest boblat...@gmail.com wrote: Hello all, given two vectors X and Y I'd like to receive a vector Z which contains, for each element of X, the index of the corresponding element in Y (or NA if that element isn't in Y). Example: x - c(4,5,6) y -

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Robert Latest
Hi guys, like so often, the answert came to me minutes after posting. pmatch() does exactly what I need. match() gives the values of the elements, but not their positions. Thanks, robert __ R-help@r-project.org mailing list

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Pascal Oettli
Hello, ?match x - c(4,5,6) y - c(10,1,5,12,4,13,14) match(x,y) [1] 5 3 NA Hope this helps, Pascal Le 12/02/2013 19:09, Robert Latest a écrit : Hello all, given two vectors X and Y I'd like to receive a vector Z which contains, for each element of X, the index of the corresponding

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Duncan Murdoch
On 13-02-12 5:18 AM, Robert Latest wrote: Hi guys, like so often, the answert came to me minutes after posting. pmatch() does exactly what I need. match() gives the values of the elements, but not their positions. I think you should read the docs more closely. match() does what you need;

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Nordlund, Dan (DSHS/RDA)
-help-bounces@r- project.org] On Behalf Of Pascal Oettli Sent: Tuesday, February 12, 2013 2:21 AM To: Robert Latest Cc: r-help@r-project.org Subject: Re: [R] Is there a neat R trick for this? Hello, ?match x - c(4,5,6) y - c(10,1,5,12,4,13,14) match(x,y) [1] 5 3 NA Hope

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Bert Gunter
Latest Cc: r-help@r-project.org Subject: Re: [R] Is there a neat R trick for this? Hello, ?match x - c(4,5,6) y - c(10,1,5,12,4,13,14) match(x,y) [1] 5 3 NA Hope this helps, Pascal Le 12/02/2013 19:09, Robert Latest a écrit : Hello all, given two vectors X and Y I'd

Re: [R] Is there a neat R trick for this?

2013-02-12 Thread Nordlund, Dan (DSHS/RDA)
- From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] Sent: Tuesday, February 12, 2013 11:37 AM To: Nordlund, Dan (DSHS/RDA); r-help@r-project.org Subject: Re: [R] Is there a neat R trick for this? but that doesn't maintain the sequence of the original data