updated r_between to include grouping