# How can I merge lists using Riffle and Partition, when I need a function?

**URL:** <https://community.wolfram.com/t/how-can-i-merge-lists-using-riffle-and-partition-when-i-need-a-function/2942>\
**Category:** Questions\
**Tags:** mathematica\
**Created:** [August 12, 2014, 8:06pm UTC](https://community.wolfram.com/t/how-can-i-merge-lists-using-riffle-and-partition-when-i-need-a-function/2942 "2014-08-12T20:06:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![meklon](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@meklon](https://community.wolfram.com/u/meklon)\
**Post date:** [August 12, 2014, 8:06pm UTC](https://community.wolfram.com/t/how-can-i-merge-lists-using-riffle-and-partition-when-i-need-a-function/2942/1 "2014-08-12T20:06:30Z")

</div>

I’ve got the data, containing the values in 5 studies and the days in the first column.  
I am trying to create the ErrorListPlot, but I’ve got the problem with syntax.

```
Needs["ErrorBarPlots`"]

pathTransplant = 
  "C:UsersMeklonownCloudRegenLabDataWeightTransplant_
weight.xlsx";

dataTransplant1Weight = Import[pathTransplant, {"Data", 1, All, 2}];
dataTransplant2Weight = Import[pathTransplant, {"Data", 1, All, 3}];
dataTransplant3Weight = Import[pathTransplant, {"Data", 1, All, 4}];
dataTransplant4Weight = Import[pathTransplant, {"Data", 1, All, 5}];
dataTransplant5Weight = Import[pathTransplant, {"Data", 1, All, 6}];
dataTransplantWeight = List[dataTransplant1Weight, dataTransplant2Weight, dataTransplant3Weight, dataTransplant4Weight, dataTransplant5Weight];

dataDay = Import[pathTransplant, {"Data", 1, All, 1}];
meanTransplant = Mean[dataTransplantWeight];
standardErrorTransplant = StandardDeviation[dataTransplantWeight]/Sqrt[Length[dataTransplantWeight]];

plotDataTransplant = Partition[Riffle[dataDay, meanTransplant], 2]
plotDataTransplantErr = Partition[Riffle[plotDataTransplant, standardErrorTransplant], 2]

ErrorListPlot[plotDataTransplantErr]

```

The problem is with _plotDataTransplantErr = Partition[Riffle[plotDataTransplant, standardErrorTransplant], 2]_  
It gives me the output like this:

```
{{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}...

```

It is practically what I need, but I cannot insert the text “ErrorBar” in it, as I need something like this for input of **ErrorListPlot** :

```
{{{0., 245.6}, ErrorBar [3.9064]}, {{1., 204.8}, ErrorBar [3.33766]}, {{3., 202.6}, ErrorBar [2.65707]}

```

This doesn’t work either:

```
ErrorListPlot[{plotDataTransplant, ErrorBar[standardErrorTransplant]}]

```

 ![Безымянный.png](https://global.discourse-cdn.com/wolfram/original/3X/6/5/65a2cae7459e64bcbb76b2a342153abe99fb9bf5.png)

---

<div class="post-metadata">

**Author:** ![ccarter](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ccarter/32/36312_2.png) [@ccarter](https://community.wolfram.com/u/ccarter)\
**Post date:** [August 12, 2014, 8:30pm UTC](https://community.wolfram.com/t/how-can-i-merge-lists-using-riffle-and-partition-when-i-need-a-function/2942/2 "2014-08-12T20:30:11Z")

</div>

Hello,  
This is a simple solution using the slash dot Swiss Army knife:

```
expr = {{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 2.65707}}

 expr = expr/.{{a_, b_},c_}->{{a,b},ErrorBar[c]}

```

I hope this might help, WCC

---

<div class="post-metadata">

**Author:** ![meklon](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@meklon](https://community.wolfram.com/u/meklon)\
**Post date:** [August 12, 2014, 8:32pm UTC](https://community.wolfram.com/t/how-can-i-merge-lists-using-riffle-and-partition-when-i-need-a-function/2942/3 "2014-08-12T20:32:47Z")

</div>

Can you express this idea more completely? I’m using Wolfram for several weeks and it’s too hard for me to understand this sometimes) I’m a doctor))

---

<div class="post-metadata">

**Author:** ![ccarter](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ccarter/32/36312_2.png) [@ccarter](https://community.wolfram.com/u/ccarter)\
**Post date:** [August 12, 2014, 8:53pm UTC](https://community.wolfram.com/t/how-can-i-merge-lists-using-riffle-and-partition-when-i-need-a-function/2942/4 "2014-08-12T20:53:40Z")

</div>

Dear Ivan,  
Sure. I’ll try. However, I am sure that I can’t improve on the explanations in the documentation.

Slash-dot is perhaps one of the most powerful constructs in the wolfram language.

In this case:

```
  expr/.{{a_, b_},c_}->{{a,b},ErrorBar[c]}

```

could be read as the following.  
_Take expression and apply the following rule_ (slash dot is the part that says “apply the following rule”).  
The rule is take something that has this pattern:

```
{{1,2},3}

```

and turn it into something that is related to the pattern:

```
{{1,2}, ErrorBar[3]}

```

However to use this for an arbitrary thing that matches the pattern

```
 {{_,_},_}, 

```

we will need the matched pattern to keep a placeholder for the {1,2} part and the 3 part. This is where pattern matching comes in:

```
{{a_,b_}, c_}-> {a,b,ErrorBar[c]}

```

so that c\_ is a placeholder for the last member of your list and we get to use “c” as the result of the match on the right-hand-side of the arrow; and a\_ and b\_ are the placeholders for the members of the sublist. The “meaning” of a,b, and c goes away after the pattern has been used.

---

<div class="post-metadata">

**Author:** ![meklon](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@meklon](https://community.wolfram.com/u/meklon)\
**Post date:** [August 12, 2014, 9:09pm UTC](https://community.wolfram.com/t/how-can-i-merge-lists-using-riffle-and-partition-when-i-need-a-function/2942/5 "2014-08-12T21:09:02Z")

</div>

Sounds like a dark magic) But I still have the problem. It’s 1:07 here, so I should sleep for a while. Can you provide me some links to the documentation from my case? Or can you solve the current problem if you have some time. It’s hard for me to understand the problem after 12 hours of hard work(

```
plotDataTransplantErr={{{0., 245.6}, 3.9064}, {{1., 204.8}, 3.33766}, {{3., 202.6}, 
  2.65707}, {{6., 214.2}, 3.18434}, {{9., 237.}, 
  2.46982}, {{12., 272.2}, 3.81314}, {{15., 296.}, 
  2.40832}, {{18., 313.6}, 4.31972}, {{21., 323.4}, 3.88072}}
plotDataTransplantErr = plotDataTransplantErr /. {{a_, b_}, c_} -> {{a, b}, ErrorBar[c]}

```

The output is abnormal:

```
{{{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 214.2}, {9., 
     237.}, {12., 272.2}, {15., 296.}, {18., 313.6}, {21., 
     323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 
     3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 
     3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 
     3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 
     4.31972}, {{21., 323.4}, 3.88072}}}, 
  ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 
     214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 
     313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 
     214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 
     313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 
     3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 
     3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 
     3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 
     4.31972}, {{21., 323.4}, 3.88072}}}, 
  ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 
     214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 
     313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 
     214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 
     313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 
     3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 
     3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 
     3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 
     4.31972}, {{21., 323.4}, 3.88072}}}, 
  ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 
     214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 
     313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 
     214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 
     313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 
     3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 
     3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 
     3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 
     4.31972}, {{21., 323.4}, 3.88072}}}, 
  ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 
     214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 
     313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 
     214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 
     313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 
     3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 
     3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 
     3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 
     4.31972}, {{21., 323.4}, 3.88072}}}, 
  ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 
     214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 
     313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 
     214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 
     313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 
     3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 
     3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 
     3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 
     4.31972}, {{21., 323.4}, 3.88072}}}, 
  ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 
     214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 
     313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 
     214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 
     313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 
     3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 
     3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 
     3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 
     4.31972}, {{21., 323.4}, 3.88072}}}, 
  ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 
     214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 
     313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 
     214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 
     313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 
     3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 
     3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 
     3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 
     4.31972}, {{21., 323.4}, 3.88072}}}, 
  ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 
     214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 
     313.6, x}}]}, {{{{0., 245.6}, {1., 204.8}, {3., 202.6}, {6., 
     214.2}, {9., 237.}, {12., 272.2}, {15., 296.}, {18., 
     313.6}, {21., 323.4}}, {{{0., 245.6}, 3.9064}, {{1., 204.8}, 
     3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 
     3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 
     3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 
     4.31972}, {{21., 323.4}, 3.88072}}}, 
  ErrorBar[{{0., 245.6, x}, {1., 204.8, x}, {3., 202.6, x}, {6., 
     214.2, x}, {9., 237., x}, {12., 272.2, x}, {15., 296., x}, {18., 
     313.6, x}}]}}

```

---

<div class="post-metadata">

**Author:** ![ccarter](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/ccarter/32/36312_2.png) [@ccarter](https://community.wolfram.com/u/ccarter)\
**Post date:** [August 12, 2014, 9:27pm UTC](https://community.wolfram.com/t/how-can-i-merge-lists-using-riffle-and-partition-when-i-need-a-function/2942/6 "2014-08-12T21:27:53Z")

</div>

It appears that you may have already defined c previously. In that case, this will work.

```
plotDataTransplantErr = {{{0., 245.6}, 3.9064}, {{1., 204.8}, 
   3.33766}, {{3., 202.6}, 2.65707}, {{6., 214.2}, 
   3.18434}, {{9., 237.}, 2.46982}, {{12., 272.2}, 
   3.81314}, {{15., 296.}, 2.40832}, {{18., 313.6}, 
   4.31972}, {{21., 323.4}, 3.88072}}

plotDataTransplantErr = 
 plotDataTransplantErr /. {{a_, b_}, c_} :> {{a, b}, ErrorBar[c]}

```

The difference here is that :\> replaces the → (it has the same purpose here as how := replaces =).  
Sleep well, WCC

---

<div class="post-metadata">

**Author:** ![meklon](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@meklon](https://community.wolfram.com/u/meklon)\
**Post date:** [August 13, 2014, 2:41am UTC](https://community.wolfram.com/t/how-can-i-merge-lists-using-riffle-and-partition-when-i-need-a-function/2942/7 "2014-08-13T02:41:23Z")

</div>

Wonderful. You’ve helped me very much. Thanks.
