1
$\begingroup$

Let's create a sample data

data = {{0.21,0,0},{-3.2,2,1},{0.03,4,3},{3.1,0,0},{5.23,3,2},{8.02,1,1},{-2.4,2,1},{3.3,0,0},{1.02,1,1},{0.07,5,6}};

Each element of the list contains one real number and two integers. We are only interested in integers. We want to find how many different pairs of integers exist in the data list. In particular, we need to create a second list data2, containing all the different types in the form $nm$. For the above example, the list should be

data2 = {00, 21, 43, 32, 11, 56};

Any ideas?

$\endgroup$
1
  • $\begingroup$ IntegerString[#, 10, 2] & /@ FromDigits /@ DeleteDuplicates[ Cases[#, _Integer] & /@ data] $\endgroup$
    – Bob Hanlon
    May 4 '20 at 16:47
2
$\begingroup$
pairs = DeleteDuplicates @ (Rest /@ data)
{{0, 0}, {2, 1}, {4, 3}, {3, 2}, {1, 1}, {5, 6}}
ClearAll[f1, f2, f3]

f1 = Map[StringRiffle[#, ""] &] @ DeleteDuplicates @ #[[All, -2 ;;]] &;

f1 @ data
 {"00", "21", "43", "32", "11", "56"}
f2 = Map[FromDigits] @ DeleteDuplicates @ #[[All, -2 ;;]] &;

f2 @ data
 {0, 21, 43, 32, 11, 56}
f3 = Map[Row] @ DeleteDuplicates @ #[[All, -2 ;;]] &;
f3 @ data

enter image description here

$\endgroup$
6
  • $\begingroup$ Well, how you remove the first column with the unwanted real numbers? $\endgroup$
    – Vaggelis_Z
    May 4 '20 at 16:42
  • $\begingroup$ @Vaggelis_Z, Rest/@data removes the first column. $\endgroup$
    – kglr
    May 4 '20 at 16:43
  • $\begingroup$ And if we want to remove the first four columns and leave the last two ones? $\endgroup$
    – Vaggelis_Z
    May 4 '20 at 16:44
  • $\begingroup$ data[[All, -2;;]] is more general. $\endgroup$
    – kglr
    May 4 '20 at 16:47
  • 1
    $\begingroup$ maybe #/Total[#] &@Counts[data[[All, -2 ;;]]] ? $\endgroup$
    – kglr
    May 4 '20 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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