I have two data frames like this.
data1=data.frame(begin=c(1,100,50,1000), end=c(100,289,400,2000), type=c(1,1,2,3),Name=c("A","B","C","D"),ID=c("EN1","EN7","EN98","EN63"))
data2=data.frame(type=c(1,2,2,4), pos=c(98,201,256,230474), Count=c(12,15,2,30))
I need to merge the data frame like this.
begin end type Name ID Count
1 100 1 A EN1 12
100 289 1 B EN7 0
50 400 2 C EN98 17
1000 2000 3 D EN63 0
The count is based on the range's added values in each position.
with sqldf I have tried like this, but it does not consider multiple columns for merge
sqldf("select * from data2 left join data1
on (data2 == data2.begin and data2.end)