How Can You Efficiently Remove Multiple Rows from a List by ID?

  • Thread starter Thread starter raymound
  • Start date Start date
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
raymound
Messages
13
Reaction score
0
hi
I have a list which I want to drop some of it's rows
and I have the id of the rows I want to drop in a list and there's no algorythem in the list

how can I do that?
I know the Command Drop[MC, {id}] whould drop the row number id but if I put this in a loop and try to drop them one by one the id's whould change since I'm dropping some rows and I tried to figure a way out of it but the just didn't work, any help?

the first one in my list and the second one the id of the rows to be dropped

PHP:
{{0.00414938, 6.}, {0.00438052, 5.9}, {0.00460842, 5.8}, {0.00482298, 
  5.7}, {0.0050097, 5.6}, {0.00515407, 5.5}, {0.00517174, 
  5.4}, {0.00504864, 5.3}, {0.00469823, 5.2}, {0.00402235, 
  5.1}, {0.0029449, 5.}, {0.00165498, 4.9}, {-0.00110326, 
  4.8}, {-0.00556929, 4.7}, {-0.0113029, 4.6}, {-0.0183193, 
  4.5}, {-0.0258924, 4.4}, {-0.0363815, 4.3}, {-0.0540341, 
  4.2}, {-0.0762913, 4.1}, {-0.0978172, 4.}, {-0.120518, 
  3.9}, {-0.15479, 3.8}, {-0.188365, 3.7}, {-0.221846, 
  3.6}, {-0.250625, 3.5}, {-0.283568, 3.4}, {-0.276114, 
  3.3}, {-0.227546, 3.2}, {-0.129161, 3.1}, {0.0897719, 
  3.}, {0.511911, 2.9}, {1.19876, 2.8}, {2.32358, 2.7}, {4.16475, 
  2.6}, {7.02193, 2.5}, {11.4346, 2.4}, {18.2226, 2.3}, {28.5117, 
  2.2}, {44.0589, 2.1}, {67.3399, 2.}, {"", ""}}

PHP:
{2, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 15, 17, 18, 19, 20, 22, 24, 26,
28, 30, 32, 34, 36, 38, 40}
 
Physics news on Phys.org
raymound said:
if I put this in a loop and try to drop them one by one the id's would change since I'm dropping some rows

What if your loop drops them one by one starting with the end of your list instead of the beginning?

First drop row 40 and then drop row 38 and then drop row 36 ... and then drop row 2.

The number of rows remaining in your list would decrease with each iteration, but by doing this in reverse order of the id's that you still need to delete would not change.