Re: [R] table lookup n R

2004-07-15 Thread Kjetil Halvorsen
?match
%in%
Kjetil Halvorsen
Anne wrote:
Hello R helpers!
I looked  but did not find a table-lookup R-utility. I could use a loop to do the job 
(old FORTRAN/C habits die hard) but if I have a big table in which I have to search 
for the values corresponding to a vector, I end up logically with a double loop.
Is there already such a utility? Otherwise, is there a way without loops?
Thanks as always
Anne

Anne Piotet
Tel: +41 79 359 83 32 (mobile)
Email: [EMAIL PROTECTED]
---
M-TD Modelling and Technology Development
PSE-C
CH-1015 Lausanne
Switzerland
Tel: +41 21 693 83 98
Fax: +41 21 646 41 33
--
[[alternative HTML version deleted]]
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
 

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] table lookup n R

2004-07-14 Thread Don MacQueen
There is also the match() function, and the %in% operator, either of 
which might do the job, depending on your exact details. For example,

   (1:26)[letters %in% c('x','t','j')]
-Don
At 2:34 PM +0200 7/13/04, Anne wrote:
Hello R helpers!
I looked  but did not find a table-lookup R-utility. I could use a 
loop to do the job (old FORTRAN/C habits die hard) but if I have a 
big table in which I have to search for the values corresponding to 
a vector, I end up logically with a double loop.
Is there already such a utility? Otherwise, is there a way without loops?

Thanks as always
Anne

Anne Piotet
Tel: +41 79 359 83 32 (mobile)
Email: [EMAIL PROTECTED]
---
M-TD Modelling and Technology Development
PSE-C
CH-1015 Lausanne
Switzerland
Tel: +41 21 693 83 98
Fax: +41 21 646 41 33
--
[[alternative HTML version deleted]]
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

--
--
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] table lookup n R

2004-07-13 Thread Petr Pikal
Hi

On 13 Jul 2004 at 14:34, Anne wrote:

> Hello R helpers!
> I looked  but did not find a table-lookup R-utility. I could use a
> loop to do the job (old FORTRAN/C habits die hard) but if I have a big
> table in which I have to search for the values corresponding to a
> vector, I end up logically with a double loop. Is there already such a
> utility? Otherwise, is there a way without loops?

Well, if I understand you correctly, you want to find something in 
your table (data.frame)

try:

your.table==your.vector
to get TRUE/FALSE table with same dimensions as your table

and

which(your.table==your.vector, arr.ind=T)

to obtain row/col indices of TRUE values

In case you want something else please try to be more specific.

Cheers
Petr

> 
> Thanks as always
> Anne
> 
> Anne Piotet
> Tel: +41 79 359 83 32 (mobile)
> Email: [EMAIL PROTECTED]
> ---
> M-TD Modelling and Technology Development
> PSE-C
> CH-1015 Lausanne
> Switzerland
> Tel: +41 21 693 83 98
> Fax: +41 21 646 41 33
> --
> 
>  [[alternative HTML version deleted]]
> 
> __
> [EMAIL PROTECTED] mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
[EMAIL PROTECTED]

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] table lookup n R

2004-07-13 Thread Anne
Thank you! It should do the job... (it was jeust a question to know where to
look!)
Anne

- Original Message - 
From: "Adaikalavan Ramasamy" <[EMAIL PROTECTED]>
To: "Anne" <[EMAIL PROTECTED]>
Sent: Tuesday, July 13, 2004 2:45 PM
Subject: Re: [R] table lookup n R


> See match(), %in% and related functions.
>
> Description:
>
> 'match' returns a vector of the positions of (first) matches of its
> first argument in its second.
>
> '%in%' is a more intuitive interface as a binary operator, which returns
> a logical vector indicating if there is a match or not for   its left
> operand.
>
>
>
> On Tue, 2004-07-13 at 13:34, Anne wrote:
> > Hello R helpers!
> > I looked  but did not find a table-lookup R-utility. I could use a loop
to do the job (old FORTRAN/C habits die hard) but if I have a big table in
which I have to search for the values corresponding to a vector, I end up
logically with a double loop.
> > Is there already such a utility? Otherwise, is there a way without
loops?
> >
> > Thanks as always
> > Anne
> > 
> > Anne Piotet
> > Tel: +41 79 359 83 32 (mobile)
> > Email: [EMAIL PROTECTED]
> > ---
> > M-TD Modelling and Technology Development
> > PSE-C
> > CH-1015 Lausanne
> > Switzerland
> > Tel: +41 21 693 83 98
> > Fax: +41 21 646 41 33
> > --
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > [EMAIL PROTECTED] mailing list
> > https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
> >
>
>

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] table lookup n R

2004-07-13 Thread Gabor Grothendieck

Try subscripting, e.g.

   # L holds numbers; its names hold lookup keys
   L <- 1:26; names(L) <- letters
   L[c("d","f")]  # look up numbers of d and f

or merge, e.g.

   merge(c("d","f"), L, by.x = 1, by.y = 0)


Anne  urbanet.ch> writes:

: 
: Hello R helpers!
: I looked  but did not find a table-lookup R-utility. I could use a loop to 
do the job (old FORTRAN/C habits die
: hard) but if I have a big table in which I have to search for the values 
corresponding to a vector, I end up
: logically with a double loop.
: Is there already such a utility? Otherwise, is there a way without loops?
: 
: Thanks as always
: Anne

__
[EMAIL PROTECTED] mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html