Hello, I believe this works
res <- NULL for(i in 1:nrow(df1)){ brk <- df1[i, 2:3] ix <- df2$Pos >= brk$Start & df2$Pos <= brk$End res <- rbind(res, apply(df2[ix, -1], 2, mean)) } res It's not very pretty but since the ranges can overlap, I'm not finding anything prettier (without a loop). Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Averaging-within-a-range-of-values-tp4291958p4294017.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.