2
$\begingroup$

If I have this three lists such as the following:

list1={{0.01,0.},{0.03,0.18353},{0.1,0.494987},{0.3,0.899803},{1.,1.08076},{3.,1.10593},{10.,1.04781},{10.,1.02449},{10.,0.964193},{30.,1.0602},{30.,1.04075},{30.,1.05987},{100.,1.14661},{100.,1.00639},{100.,1.09384},{300.,1.067},{300.,1.15047},{300.,1.10715},{1000.,1.05152},{1000.,1.06942},{1000.,1.17143},{3000.,1.12162},{10000.,1.13136}}

list2={{0.01,0.},{0.03,0.},{0.1,0.12702},{0.3,0.284862},{1.,0.330209},{3.,0.490592},{10.,0.864811},{30.,0.951112},{100.,0.924481},{300.,1.02702},{1000.,1.12306},{3000.,1.061},{10000.,1.08021}}

list3={{0.01,0.},{0.03,0.},{0.1,0.215019},{0.3,0.702618},{1.,1.27573},{3.,1.02397},{10.,1.1375},{10.,1.14245},{10.,0.945541},{30.,1.33324},{30.,1.07789},{30.,1.12324},{100.,1.14999},{100.,0.985026},{100.,1.1228},{300.,1.25291},{300.,1.29771},{300.,1.40179},{1000.,1.26045},{1000.,1.17871},{1000.,1.32166},{3000.,1.27041},{10000.,1.23387}}

How can I put a given number in between each data set of each list?. For example, if I want to place the number 10 in between in list 1 it should look like: list1={{0.01,10,0.},{0.03,10,0.18353},{0.1,10,0.494987}...etc. If I want to put the number 20 in between list 2 it should look like {{0.01,20,0.},{0.03,20,0.},{0.1,20,0.12702}....etc and so on for list 3.

Thank you in advanced,

$\endgroup$
2
  • 1
    $\begingroup$ Riffle[#, 10] & /@ list1 and Riffle[#, 20] & /@ list2 etc... $\endgroup$
    – kglr
    May 2 '20 at 4:10
  • $\begingroup$ @kglr Thank you very much! This works great! Exactly what I wanted $\endgroup$
    – John
    May 2 '20 at 4:15
1
$\begingroup$
ClearAll[threadRiffle]
threadRiffle = MapThread[Map[Function[x, Riffle[x, #2]]]@# &, {##}] &;

threadRiffle[{list1, list2, list3}, {10, 20, xx}]
 {{0.01, 10, 0.}, {0.03, 10, 0.18353}, {0.1, 10, 0.494987}, {0.3, 10, 0.899803}, 
   {1., 10, 1.08076}, {3., 10, 1.10593}, {10., 10,  1.04781}, {10., 10, 1.02449}, 
   {10., 10, 0.964193}, {30., 10, 1.0602}, {30., 10, 1.04075}, {30., 10, 1.05987}, 
   {100., 10,  1.14661}, {100., 10, 1.00639}, {100., 10, 1.09384}, {300., 10,  1.067},
   {300., 10, 1.15047}, {300., 10, 1.10715}, {1000., 10,   1.05152}, 
   {1000., 10, 1.06942}, {1000., 10, 1.17143}, {3000., 10,  1.12162}, 
   {10000., 10, 1.13136}},
  {{0.01, 20, 0.}, {0.03, 20,  0.}, {0.1, 20, 0.12702}, {0.3, 20, 0.284862},
   {1., 20,  0.330209}, {3., 20, 0.490592}, {10., 20, 0.864811},
   {30., 20,  0.951112}, {100., 20, 0.924481}, {300., 20, 1.02702}, 
   {1000., 20,  1.12306}, {3000., 20, 1.061}, {10000., 20, 1.08021}}, 
   {{0.01, xx,  0.}, {0.03, xx, 0.}, {0.1, xx, 0.215019}, {0.3, xx, 0.702618}, 
  {1.,  xx, 1.27573}, {3., xx, 1.02397}, {10., xx, 1.1375}, 
   {10., xx,  1.14245}, {10., xx, 0.945541}, {30., xx, 1.33324}, 
   {30., xx,  1.07789}, {30., xx, 1.12324}, {100., xx, 1.14999}, 
   {100., xx,  0.985026}, {100., xx, 1.1228}, {300., xx, 1.25291}, 
   {300., xx, 1.29771}, {300., xx, 1.40179}, {1000., xx, 1.26045}, 
   {1000., xx,  1.17871}, {1000., xx, 1.32166}, {3000., xx, 1.27041}, 
   {10000., xx, 1.23387}}}

Alternatively, you can use Insert instead of Riffle:

ClearAll[threadInsert]
threadInsert[p_: 2] := MapThread[Map[Function[x, Insert[x, #2, p]]]@# &, {##}] &;

threadInsert[][{list1, list2, list3}, {10, 20, xx}] == 
  threadRiffle[{list1, list2, list3}, {10, 20, xx}]
True
$\endgroup$

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.