Quantcast
Channel: Adding elements to some sublists of unequal length - Mathematica Stack Exchange
Browsing latest articles
Browse All 4 View Live

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

You can make b into a list of rules rules = {#, a__} :> {#, a, #2} & @@@ b; and use it with ReplaceAll: a /. rules {{1, 3, 5, 2}, {2, 6, 2, 1}, {3, 5, 6, 1, 2}, {4, 2, 3}} or with Replace:...

View Article



Answer by Suba Thomas for Adding elements to some sublists of unequal length

Fold[Insert[#1, Last[#2], {First[#2], -1}] &, a, b]

View Article

Answer by Vitaliy Kaurov for Adding elements to some sublists of unequal length

Perhaps something like this: ReplacePart[a, #1 -> Append[a[[#1]], #2]& @@@ b] If data are large and speedup is needed you might want to try Join ReplacePart[a, #1 -> Join[a[[#1]], {#2}] &...

View Article

Adding elements to some sublists of unequal length

Complicated title for a simple problem: I have list a = {{1, 3, 5, 2}, {2, 6, 2}, {3, 5, 6, 1, 2}, {4, 2}} In which the first element of each sublist is basically an index. The following values are...

View Article
Browsing latest articles
Browse All 4 View Live


Latest Images