Can you give us some sample code (minimal working example) and perhaps the data in a more usable format?
See FAQ: Tips for writing R-related questions.
A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need.