My recent question was not as clear as it could have been:

I'd like to rephrase it.

I have lis, a list of records. Each record consists of one (of two possible) dates, a parameter name, a numerical value, another parameter name, another numerical value, and a miscellaneous parameter name; 6 sub-elements in each element of lis, as can be seen below:

lis = {
  {DateObject[{2000, 1, 1}], "a", 1, "b", 2, "w"},
  {DateObject[{1999, 12, 31}], "a", 1, "b", 2, "w"},
  {DateObject[{2000, 1, 1}], "a", 1, "c", 2, "w"},
  {DateObject[{1999, 12, 31}], "a", 1, "c", 3, "w"},
  {DateObject[{1999, 12, 31}], "b", 1, "c", 2, "w"}

The rules to be applied to get desired res include:

1) There are pairs of records which are identical, apart from date. With these pairs, I'd like to delete the older record and pass the newer record to res.

2) There are also pairs from different dates where the parameters are identical, but their values may be different. I will would like to pass both these pairs to res as well.

3) There will be elements with older dates where the parameter names and values will not match any of the elements with the newest date. These elements with the older dates that do not match those with newer dates should be dropped and not passed on to res.

So we have:

res = {
  {DateObject[{2000, 1, 1}], "a", 1, "b", 2,"w"}, 
  {DateObject[{2000, 1, 1}], "a", 1, "b", 3,"w"}, 
  {DateObject[{1999, 12, 31}], "a", 1, "b", 2, "w"}
  • $\begingroup$ Ad 3) what does "older dates" mean when you say that no names/values match. Older with respect to what? What if the last one from lis is from 2001? Anyway, have you tried anything? $\endgroup$
    – Kuba
    Sep 3, 2018 at 8:22
  • $\begingroup$ i. Your result violates your rule 1. ii. Your rule 3 is unclear. iii. This should get you started: <|Rest[#] -> First[#] & /@ Sort[lis]|> $\endgroup$
    – Alan
    Sep 3, 2018 at 12:04
  • $\begingroup$ @Kuba I read (i) to say that the final item in his res should have been dropped because it exactly matches the first item aside from the date. $\endgroup$
    – Alan
    Sep 3, 2018 at 14:43
  • $\begingroup$ Thanks for the analysis. I have been less than clear. I will restate in a new question. $\endgroup$
    – Suite401
    Sep 3, 2018 at 19:29
  • $\begingroup$ @Alan you are right, I was confused because the middle result does not even exist in the input. I think I assumed it is the a/c/w pair left by (ii). Thanks. $\endgroup$
    – Kuba
    Sep 4, 2018 at 5:47


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.