Reshape a numeric variable in a dataframe according to a factors in another column
<p>I've been experimenting with a lot of R codes such as <code>melt()</code>, <code>split()</code>, <code>reshape()</code>, but none of them was able to really solve my problem. I would like to create a new df based on the one underneath that doesn't have the <code>Long_group</code> and <code>B_lymph_count</code> any more but instead has three different columns, namely "Aubagio_0", "Aubagio_1" and "Aubagio_2" that contain the values of the corresponding <code>B_lymph_counts</code> for the specific <code>MS.number</code> = patient ID. </p>

<h1>Current df:</h1>

<pre><code>MS.number  B_Lymph_count Long_group 
13  "MS072/1"  " 57014"      "Aubagio_0"
14  "MS072/1"  "116730"      "Aubagio_1"
46  "MS1246/1" "117843"      "Aubagio_0"
47  "MS1246/1" "209583"      "Aubagio_1"
52  "MS1253/1" " 71434"      "Aubagio_0"
53  "MS1253/1" "130382"      "Aubagio_1"
100 "MS717/1"  " 63916"      "Aubagio_0"
101 "MS717/1"  " 62434"      "Aubagio_1"
102 "MS717/1"  " 43533"      "Aubagio_2"
</code></pre>

<h1>Df I want to produce</h1>

<pre><code>MS.number  Aubagio_0 Aubagio_1 Aubagio_2
MS717/1       63916        62434     43533
MS1253/1      71434        130382     NA
...
</code></pre>

<p>Hope this is possible in R.
Thank you already very much for the reply!</p>