s-news
[Top] [All Lists]

Re: Function to find closest/matching value

To: "Lambert.Winnie" <lambert.winifred@ensco.com>
Subject: Re: Function to find closest/matching value
From: Sundar Dorai-Raj <sundar.dorai-raj@pdf.com>
Date: Thu, 09 May 2002 15:22:19 -0500
Cc: s-news@lists.biostat.wustl.edu
Organization: PDF Solutions, Inc.
References: <8986151694190742869D08450EE4DCDE08ECFA@amu-exch.ensco.win>
Try which()

> myDF <- data.frame(x1=runif(4),x2=1:4)
> myNum <- 2
> which(myDF[,2]==myNum)
[1] 2
> myDF[,2]==myNum
[1] F T F F

Is this what you had in mind? I can't say if it will be any faster, but
maybe...

Sundar

"Lambert.Winnie" wrote:
> 
> S-PLUS 6 R2 MSWindows 2000
> 
> All,
> 
> I have a dataframe with 11,000,000 rows and 2 columns (call it myDF).  I need 
> to match a number (myNum) with a value in the second column in order to find 
> the value I want in the first column so that myNum == myDF[?,2].  Given that 
> the dataframe is so huge, I want to refrain from creating a logical vector 
> and subscripting to find the correct row in the data frame.  It takes too 
> long and too much memory, and I need to do these matches with lots of 
> numbers.  Is there a function that will take as input myNum and match it with 
> a value in myDF[,2] and at least give me the row number?  I looked at match 
> and it did not do what I wanted, unless I did not enter things correctly.  I 
> prefer not to make myDF smaller.
> 
> ***********************************************************************
> Winifred C. Lambert                Senior Scientist/Meteorologist
> ENSCO, Inc.
> Aerospace Sciences and Engineering Division
> 1980 N. Atlantic Ave, Suite 230
> Cocoa Beach, FL  32931
> VOICE: 321.853.8130  FAX: 321.853.8415
> lambert.winifred@ensco.com
> 
> AMU Quarterly Reports are available online:
> http://science.ksc.nasa.gov/amu/home.html
> ***********************************************************************
> --------------------------------------------------------------------
> 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

-- 

Sundar Dorai-Raj, Ph.D.
Statistical Methods Engineer
PDF Solutions, Inc.
Richardson TX
(972) 889-3085 x216
(214) 392-7619 cell
sundar.dorai-raj@pdf.com

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