4

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!

user18537
  • 41
  • 2

2 Answers2

2

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.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
1
data={{1,2,3,4},{5,6,7,8},{9,10,11,12}}

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

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

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

and many more possibilities

eldo
  • 67,911
  • 5
  • 60
  • 168