I have a data frame that contains tagged individuals at multiple sites from multiple sampling intervals. See example below:

```
> df
   Tag   Site Interval Ind_ID
1  507 Golden        7      1
2  507 Golden        8      1
3  552 Golden        2      1
4  552 Golden        1      1
5  847 Golden        4      1
6  847 Golden        6      1
8  847 Golden        5      1
9  847 Golden        3      1
31 541 Golden        1      1
33 541 Golden        3      1
34 541 Golden        4      1
35 541 Golden        7      1
36 541 Golden        6      1
37 541 Golden        5      1
39 810 Golden        7      1
40 810 Golden        8      1
41 840 Golden        7      1
42 840 Golden        8      1
43 840 Golden        3      1
44 840 Golden        2      1

```

What I'm trying to do is separate tagged individuals by interval, which I've done using this for loop:

```
for (i in 1:nlevels(factor(df$Interval))){
  I<-subset(df,Interval==levels(factor(df$Interval))[i])
  assign(paste("Interval_", i, sep = ""), I)}

```

And then merge data frames by pairs in sequence, which I'm currently doing using this code:

```
IPl2<-merge(Interval_1, Interval_2, by=c("Tag", "Site", "Ind_ID"))
IPl3<-merge(Interval_2, Interval_3, by=c("Tag", "Site", "Ind_ID"))
IPl4<-merge(Interval_3, Interval_4, by=c("Tag", "Site", "Ind_ID"))
IPl5<-merge(Interval_4, Interval_5, by=c("Tag", "Site", "Ind_ID"))
IPl6<-merge(Interval_5, Interval_6, by=c("Tag", "Site", "Ind_ID"))
IPl7<-merge(Interval_6, Interval_7, by=c("Tag", "Site", "Ind_ID"))
IPl8<-merge(Interval_7, Interval_8, by=c("Tag", "Site", "Ind_ID"))

```

I'm sure there's a more efficient way of doing this. Also, I'm continually adding data to the data set (i.e. more intervals), and I would like to avoid having to edit the code each time new data is added. Any ideas?