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.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityI 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.
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]
loadeddata[[All, 1 ;; 2]]
?
$\endgroup$
– Kuba♦
Sep 26 '16 at 9:22
loadeddata[[All, {1, 2}]]
orloadeddata[[All, 1 ;; 2]]
$\endgroup$ – Bob Hanlon Sep 26 '16 at 2:47