Skip to content
Back to formatted view

Raw Message

Message-ID: <41681.5038.qm@web162012.mail.bf1.yahoo.com>
Date: 2011-06-02T18:42:56Z
From: Filippo Beleggia
Subject: complex search between dataframes

Hi!

I am very new to R, I hope someone can help me.

I have two dataframes:

data1<-data.frame(from=c(1,12,16,40,55,81,101),to=c(10,13,23,45,67,99,123))
data2<-data.frame(name=c(1,2,3,4,5,6,7,8,9),position=c(2,14,20,50,150,2000,2001,2002,85))


I want to know which of the entries in "position" of data2 are included between 
any "from" and the corresponding "to" of data1.

So in this case I would need to somehow be able to extract 2,20 and 85, 
corrisponding to the "name"s 1,3 and 9.

Thank you very much!
Filippo