4

I have the following text: loadeddata={{1,2,3},{5,2,1},{1,4,1},{1,5,0},{2,3,5}}

How can I removed the third numbers in each of the sublists?

The real data has 600 of these sublists. I want to use Histogram3D with the first two variables.

Shawn
  • 43
  • 2

1 Answers1

4

Here's a convenience function for you:

DropColumn[mat_, n_] := Module[
    {toDrop, toKeep, numberOfColumns, normalized, fixNegs},
    numberOfColumns = Length[mat[[1]]];
    fixNegs = Function[If[Less[#, 0], numberOfColumns + # + 1, #]];
    toDrop = If[ListQ[n], Map[fixNegs, n], {fixNegs @ n}];
    toKeep = Complement[Range @ numberOfColumns, toDrop];
    Return[mat[[All, toKeep]]]
   ];

Here's how you use it:

loadeddata = {{1, 2, 3}, {5, 2, 1}, {1, 4, 1}, {1, 5, 0}, {2, 3, 5}};
loadeddata = DropColumn[loadeddata, 3]

enter image description here

M.R.
  • 31,425
  • 8
  • 90
  • 281