Quantcast
Channel: Adding elements to some sublists of unequal length - Mathematica Stack Exchange
Viewing all articles
Browse latest Browse all 7

Answer by Syed for Adding elements to some sublists of unequal length

$
0
0
Clear["Global`*"];a = {{1, 3, 5, 2}, {2, 6, 2}, {3, 5, 6, 1, 2}, {4, 2}};b = {{2, 1}, {4, 3}};c = Join[b, Array[{#, x} &, Length@a]] // DeleteDuplicatesBy[First] //   SortBy[First]

{{1, x}, {2, 1}, {3, x}, {4, 3}}

Using Join:

Join the second column of c with a and delete the x:

Join[a, List /@ c[[All, 2]], 2] /. x -> Nothing

{{1, 3, 5, 2}, {2, 6, 2, 1}, {3, 5, 6, 1, 2}, {4, 2, 3}}


Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>