[R] complex search between dataframes

Filippo Beleggia fbeleggia at yahoo.com
Thu Jun 2 20:42:56 CEST 2011


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



More information about the R-help mailing list