s-news
[Top] [All Lists]

Re: conditional rows selecting from a data frame ['Watchdog': checked]

To: s-news@lists.biostat.wustl.edu
Subject: Re: conditional rows selecting from a data frame ['Watchdog': checked]
From: Paul Matthias Diderichsen <paulmatthias.diderichsen@abbott.com>
Date: Fri, 14 Jul 2006 14:37:52 -0500
In-reply-to: <C8696843AE995F4EA4CDC3E2B83482A90187906A@mailbox02.cshl.edu>
Dear Sohail,

s-news-owner@lists.biostat.wustl.edu wrote on 07/05/2006 01:09:01 PM:
> I have two data frames as follows:
> df1
> probe   start   end
> xyz   20   70
> ....   ....   ....
> 
> df2
> frag   start   end
> fg1   10   100
> ...   ....   ....
> 
> I would like to read probe, start and end from df1, compare it to 
> start, end in df2.  If the start and end of df1 falls within start 
> and end of df2, I want to print probe start and end from df1, 
> otherwise ignore it.

Is the number of rows the same for df1 and df2? If so, I guess that you 
want to compare the data frames row by row? In that case, I think that the 
following should work (excuse me if it doesn't - I don't have access to S 
on this computer...):

df1[c("start","end"),df1$start>df2$start & df1$end<df2$end]

If this doesn't run, you may use the rbind function to create a new data 
frame, df3, from df1 and df2 and then do the boolean row selection on df3. 
You would have to rename the start and end columns of df2 (or df1) before 
rbinding, though.

Again, I hope this works. Otherwise, please disregard this message - in 
fact, forget that you ever read it... ;-)

Kind regards, PMD.

============================================================================================================================
The information contained in this communication is confidential, may be subject 
to legal privileges, may constitute inside information, and is intended only 
for the use of the addressee.  It is the property of Abbott Laboratories or its 
relevant affiliate.  Unauthorized use, disclosure or copying of this 
communication or any part thereof is strictly prohibited and may be unlawful.  
If you have received this communication in error, please notify Abbott 
Laboratories immediately by return e-mail and destroy this communication and 
all copies thereof, including all attachments.
=============================================================================================================================

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