The first part is just: GatherBy[data, Last] You'll have to explain in more detail what you mean by: > How do I test whether these two data sets are linearly independent?