Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have data in a list called megadata where megadata[[1]] for instance are the temperatures of each data point, megadata[[2]] are the pressures, etc. We are trying to selectively remove data points to see how it changes our fits but I have been unable to get Delete or Drop or anything else to work. I need something to let me remove the same position from every nested list within the list. So for instance if I wanted to delete positions 2 and 3 I need something to change megadata = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}} into `megadata = {{1, 4}, {5, 8}, {9, 12}.

Edit: I'm really new to Mathematica (learning ahead of the semester as part of undergraduate research) so I'm having trouble understanding some of the comments made. I used the Drop[#, {2, 3}] & /@ megadata idea and it worked quite nicely for removing adjacent points but my nested lists have a length of 12 and when I would try using it as Drop[#, {4, 7}] & /@ megadata, it seemed to remove all the points between 4 and 7 (so it would remove 4,5,6, and 7). Is there anyway to modify this format slightly to make it not remove that whole range of points and only remove 4 and 7?

Edit 2: I actually think I found the answer. Didn't see the link to the duplicate answer above. Sorry real new to all of this. Thanks for all the help though!

share|improve this question

marked as duplicate by Mike Honeychurch, Öskå, m_goldberg, RunnyKine, Mr.Wizard Jul 15 '14 at 23:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

megadata[[All, {1, 4}]] – Mike Honeychurch Jul 15 '14 at 22:59
This is closely related to Manipulating a sublist based on position although there are even closer posts, you should find them. – Artes Jul 15 '14 at 23:00
If you want to remove points i order to test a fit then I'd suggest using Cases with some sort of condition applied to a pattern. But we'd need an example of your real data. – Mike Honeychurch Jul 15 '14 at 23:03
@artes Your +1 and accepted answer in the cited link is somehow but not "closely" related :) – eldo Jul 15 '14 at 23:21
@eldo Thanks for an upvote, however a remark is needed, there is some kind of relativity in the concept of distance, so I don't insist that it is universal. When it comes to this problem I have to ask why you don't use a simpler and nicer approach: list /. {a_, b_, c_, d_} :> {a, d}? – Artes Jul 15 '14 at 23:37

Part[#, {1, -1}] & /@ data

{{1, 4}, {5, 8}, {9, 12}}

Cases[data, {a_, __, b_} :> {a, b}]

and many more possibilities

share|improve this answer
you don't need to use Map. see my comment above – Mike Honeychurch Jul 15 '14 at 23:04
@Mike Thanks for the tip :) – eldo Jul 15 '14 at 23:14
data[[All,{1,-1}]] but my other comment was more like DeleteCases[data, {a_/;some condition, __, b_/;maybe condition here too}] etc because he wants to remove points from a fit – Mike Honeychurch Jul 15 '14 at 23:18

Both Delete and Drop should certainly work if used with Map.

data = Partition[Range[4 4], 4]
{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 16}}
Drop[#, {2, 3}] & /@ data
Delete[#, {{2}, {3}}] & /@ data

Both return

{{1, 4}, {5, 8}, {9, 12}, {13, 16}}

But as eldo points out, Map can be avoided.

data[[All, {1, 4}]]

also works. Notice in this last case, you specify the columns you want to keep, rather than the ones you want to drop.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.