Message Boards Message Boards

0
|
8608 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Is it possible to delete entries by partial criteria?

Posted 10 years ago
May I first apologise for a longish post and asking 2 questions.

Here is a list that is best viewed in tableform.  see below, It has been created from 2 seperate text files and sorted to this criteria,

lis = SortBy[lis, {-#[[4]], #[[1]], #[[5]]} &]

 I now ultimately wish to delet from this list full rows where there are duplicate entries in Column[[1]] within catagory [[4]] leaving the lesser entry in [[5]]. It maybe easier to show what I mean. There are only 2 entries that meet this criteria namely these 2

Treesprite 193018 100 1000 909
Treesprite 193018 100 1000 959

I wish to delete the full entry corresponding to the greater number in the last column i.e. 959 to leave just the entry 

Treesprite 193018 100 1000 909.

Now it could transpire that the list contains more than 1 duplicate entry i.e. multiple names that needs to be deleted and even some entries where there are 3 and above with the same name, for example the table could contain this.

Treesprite 193028 100 1000 321
Treesprite 193015 100 1000 860
Treesprite 193052 100 1000 909
Treesprite 193002 100 1000 959

and in that case I would only want the 321 entry to remain. Now, I have implemented this by reading consecutive entries and then adding them to another list if consecutive entries are different, my question at this point is, is there a more efficient way to achieve this? I have tried using DeleteDuplicates, but unless there is some undocumented method I can't do what I need to do as DeleteDuplicates tests full entries and doesnt find any duplicates in this case. Select would also seem a good choice of comand yet again if that way is possible it eludes me.
Now, this list will eventually be seperated into upto 4 smaller groups delemited by the 4th column, i.e. a sub group with just 1000 entries and similarly with the other 990, 980, 970, 960 headings (not all entries will be present it can be any permutaion of 4 of the 5). The smaller sub groups won't have that column anymore and it will be sorted by what is column[[5]] atm and then column[[3]] & column[[2]] with some form of higlight if there are the same numbers in the last column. These entries illustrates that point.

Corlisa         193017 77 990 977
Doctorbobo 193025 77 990 977

Those numbers have been altered to illustrate the point, in that case the sort would go down to 193017 being smaller than 193025.My last question would be, would this problem be easier to seperate the list into sub groups first and then look for the duplicates or as I explained in the begining? 

 lis={{"Ardbeg", 192959, 84, 1000, 588}, {"Balogh", 193005, 68, 1000,
 
   571}, {"Borammar", 193112, 61, 1000, 832}, {"Charla", 193019, 77,
   1000, 46}, {"Cokkie", 193011, 60, 1000, 105}, {"Corlisa", 193010,
   77, 1000, 5}, {"Doctorbobo", 193044, 77, 1000, 878}, {"Enomis",
   193009, 77, 1000, 435}, {"Girtan", 193013, 70, 1000,
   628}, {"Hazimil", 193004, 65, 1000, 703}, {"Istanora", 193010, 100,
   1000, 777}, {"Kaninopaf", 193014, 56, 1000, 864}, {"Knerrar",
   193100, 61, 1000, 401}, {"Kubaba", 193038, 72, 1000,
  649}, {"Langleef", 193012, 89, 1000, 237}, {"Lean", 193022, 98,
  1000, 647}, {"Milaria", 193050, 72, 1000, 914}, {"Mythrill", 193022,
  81, 1000, 121}, {"Pitil", 193009, 100, 1000, 858}, {"Pondorra",
  193012, 93, 1000, 132}, {"Raryel", 193022, 91, 1000,
  804}, {"Ravaril", 193005, 100, 1000, 60}, {"Shadowbeaver", 193100,
  61, 1000, 638}, {"Treesprite", 193018, 100, 1000,
  909}, {"Treesprite", 193018, 100, 1000, 959}, {"Xpoc", 193008, 65,
  1000, 22}, {"Zandy", 193013, 84, 1000, 268}, {"Aggroraa", 192957,
  100, 990, 742}, {"Ardbeg", 193006, 84, 990, 928}, {"Balogh", 193036,
  68, 990, 52}, {"Borammar", 193120, 61, 990, 64}, {"Charla", 193029,
  77, 990, 367}, {"Cokkie", 193011, 60, 990, 719}, {"Corlisa",
  193017, 77, 990, 977}, {"Doctorbobo", 193025, 77, 990,
  977}, {"Enomis", 193014, 77, 990, 948}, {"Girtan", 193019, 70, 990,
  713}, {"Hazimil", 193004, 65, 990, 83}, {"Kaninopaf", 193017, 56,
  990, 313}, {"Kardin", 193012, 91, 990, 294}, {"Knerrar", 193106, 61,
  990, 259}, {"Kubaba", 193041, 72, 990, 964}, {"Lean", 193025, 98,
  990, 981}, {"Milaria", 193054, 72, 990, 930}, {"Mythrill", 193027,
  81, 990, 354}, {"Pitil", 193027, 100, 990, 855}, {"Pondorra",
  193016, 93, 990, 259}, {"Raryel", 193029, 91, 990, 66}, {"Ravaril",
  193013, 100, 990, 49}, {"Shadowbeaver", 193109, 61, 990,
  230}, {"Treesprite", 193030, 100, 990, 777}, {"Xpoc", 193012, 65,
  990, 959}, {"Zandy", 193017, 84, 990, 491}, {"Cokkie", 193010, 60,
  980, 382}, {"Hazimil", 193003, 65, 980, 668}, {"Aggroraa", 193001,
  100, 970, 773}, {"Balogh", 193014, 68, 970, 154}, {"Borammar",
  193133, 61, 970, 709}, {"Cokkie", 193010, 60, 970, 310}, {"Corlisa",
  193029, 77, 970, 830}, {"Doctorbobo", 193033, 77, 970,
  787}, {"Enomis", 193019, 77, 970, 215}, {"Girtan", 193025, 70, 970,
  111}, {"Kaninopaf", 193021, 56, 970, 429}, {"Knerrar", 193115, 61,
  970, 771}, {"Kubaba", 193044, 72, 970, 197}, {"Lean", 193029, 98,
  970, 413}, {"Milaria", 193101, 72, 970, 798}, {"Mythrill", 193032,
  81, 970, 23}, {"Pitil", 193023, 100, 970, 329}, {"Pondorra", 193024,
  93, 970, 541}, {"Raryel", 193034, 91, 970, 678}, {"Ravaril",
  193021, 100, 970, 859}, {"Zandy", 193020, 84, 970, 212}, {"Cokkie",
  193010, 60, 960, 643}}//TableForm

Paul.
POSTED BY: Paul Cleary
2 Replies
Just a warning to be careful and  not to evaluate the first definition shown above right away. Ends up terminating Mathematica kernel and there is a chance one could lose some work if not saved before. I am using V 9.01 on windows 7

POSTED BY: Nasser M. Abbasi
Posted 10 years ago
Could that be because list needed to be defined first?  It was in my main code but as i didn't think that it would be missing, though I don't see anything amiss with that line of code.  I have the same version and Win7 also.  I have just copied the code from here and ran it ok as it is written.  did you have the list copied in memory before you ran that line?
POSTED BY: Paul Cleary
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract