I added the perport code, and modified the loops in the frame code.  I'm still testing (so some of my testing code is still in there - sorry), and it's very very slow right now.

Before, I had been subsetting the data in the nested for loops, but now instead I am using which() to call the desired indices in order to speed it up a little bit (because subsetting a whole data set is pretty slow).

The nested for loops are really what makes it slow, but I can't figure out how to do this process without for loops.