Skip to main content
edited body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456

This is a straightforward application of GatherBy and Map (\@/@):

First /@ GatherBy[mydata, First]

(* {{1, a, aa}, {2, d, dd}, {3, f, ff}, {4, i, ii}, {5, n, nn}, {7, p, pp}} *)

You could also use Part ([[]]) to get the first element of each group.

GatherBy[mydata, First][[All,1]]

This is a straightforward application of GatherBy and Map (\@):

First /@ GatherBy[mydata, First]

(* {{1, a, aa}, {2, d, dd}, {3, f, ff}, {4, i, ii}, {5, n, nn}, {7, p, pp}} *)

You could also use Part ([[]]) to get the first element of each group.

GatherBy[mydata, First][[All,1]]

This is a straightforward application of GatherBy and Map (/@):

First /@ GatherBy[mydata, First]

(* {{1, a, aa}, {2, d, dd}, {3, f, ff}, {4, i, ii}, {5, n, nn}, {7, p, pp}} *)

You could also use Part ([[]]) to get the first element of each group.

GatherBy[mydata, First][[All,1]]
Source Link
Verbeia
  • 34.5k
  • 10
  • 110
  • 225

This is a straightforward application of GatherBy and Map (\@):

First /@ GatherBy[mydata, First]

(* {{1, a, aa}, {2, d, dd}, {3, f, ff}, {4, i, ii}, {5, n, nn}, {7, p, pp}} *)

You could also use Part ([[]]) to get the first element of each group.

GatherBy[mydata, First][[All,1]]