I have a data set in which I need to remove all matched pairs of entries - not just the first entry that is duplicated but both entries. To add to the complexity, the pairs must be between different columns of the data set.
So if I generate an example data set as follows:
SeedRandom[2]
dataSet =
Table[{DatePlus[Take[DateList[], 2], i], RandomInteger[{1, 30}],
RandomInteger[{1, 30}]}, {i, 50}];
Grid[%]
To yield a data set of:
{
{{2014, 6, 2}, 8, 4},
{{2014, 6, 3}, 5, 4},
{{2014, 6, 4}, 7, 4},
{{2014, 6, 5}, 0, 1},
{{2014, 6, 6}, 0, 4},
{{2014, 6, 7}, 3, 7},
{{2014, 6, 8}, 3, 0},
{{2014, 6, 9}, 2, 7},
{{2014, 6, 10}, 8, 7},
{{2014, 6, 11}, 3, 6}
}
I want to remove any rows in which a value in column 2 matches a value in column 3 (please ignore the date column [[1]] as it is not relevant at the moment). If a match is found between values in column 2 and 3 then both entries should be removed. Zero entries should be ignored and left in the data set so the resultant data set would look like:
{
{{2014, 6, 2}, 8, 4},
{{2014, 6, 3}, 5, 4},
{{2014, 6, 5}, 0, 1},
{{2014, 6, 6}, 0, 4},
{{2014, 6, 8}, 3, 0},
{{2014, 6, 9}, 2, 7},
{{2014, 6, 10}, 8, 7},
{{2014, 6, 11}, 3, 6}
}
Note that the actual data set only has a non-zero entry in one of the two columns for a row but it was too difficult for me to reproduce this easily for this example data.
I am unable to get DeleteDuplicates to do what I want so am stumped as to what to do.
My apologies, it looks like my earlier edits did not stick. I'll reformat the data to remove the ambiguity (note goal posts are not moving - just additional clarification of the data).
Generate example data:
SeedRandom[2]
dataSet =
Table[{Junk, RandomInteger[{0, 8}], RandomInteger[{0, 8}]}, {i,
10}];
Grid[%]
{
{Junk, 8, 4},
{Junk, 5, 4},
{Junk, 7, 4},
{Junk, 0, 1},
{Junk, 0, 4},
{Junk, 3, 7},
{Junk, 3, 0},
{Junk, 2, 7},
{Junk, 8, 7},
{Junk, 3, 6}
}
Output:
{
{Junk, 8, 4},
{Junk, 5, 4},
{Junk, 0, 1},
{Junk, 0, 4},
{Junk, 3, 0},
{Junk, 2, 7},
{Junk, 8, 7},
{Junk, 3, 6}
}
Hopefully that removes the ambiguity of the first column and enables us to concentrate on columns 2 and 3.
I do apologise for the confusion.
I will go through all the answers as I'm sure there are already some that demonstrate a good solution.