title: Filling empty dataframe in R with data
body: <p>I have created an empty data frame as described in the code below. I am trying to extract the expression data from the samples and use this to fill the data frame.</p>
  <p>Also, if a sample does not contain an expression value for a particular mRNA in the data frame how would I input a 0 into the cell instead of an NA?</p>
  <p>Any help would be very appreciated!</p>
  <p>Sample code:</p>
  <pre class="lang-r prettyprint-override"><code>sample_8765 &lt;- data.frame(type = c(&quot;protein&quot;, &quot;mRNA&quot;, &quot;mRNA&quot;, &quot;mRNA&quot;, &quot;protein&quot;),
                            name = c(&quot;DIABLO&quot;, &quot;X1345&quot;, &quot;X1234&quot;, &quot;F1234&quot;, &quot;p53&quot;),
                            expression = c(&quot;1.23&quot;, &quot;4.265&quot;, &quot;3.44&quot;, &quot;6.43&quot;, &quot;8.00&quot;))
  
  sample_8901 &lt;- data.frame(type = c(&quot;protein&quot;, &quot;mRNA&quot;, &quot;protein&quot;,&quot;mRNA&quot;, &quot;protein&quot;),
                            name = c(&quot;DIABLO&quot;, &quot;X1345&quot;, &quot;SMAC&quot;, &quot;F4657&quot;, &quot;MDM2&quot;),
                            expression = c(&quot;3.24&quot;, &quot;5.33&quot;, &quot;4.35&quot;, &quot;6.78&quot;, &quot;9.11&quot;))
  
  sample_9084 &lt;- data.frame(type = c(&quot;protein&quot;, &quot;protein&quot;, &quot;mRNA&quot;, &quot;mRNA&quot;, &quot;mRNA&quot;),
                             name = c(&quot;SMAC&quot;, &quot;DIABLO&quot;, &quot;X1345&quot;, &quot;F4657&quot;, &quot;X1234&quot; ),
                             expression = c(&quot;2.56&quot;, &quot;8.11&quot;, &quot;4.35&quot;, &quot;6.78&quot;, &quot;9.11&quot;))
  
  sample_ID &lt;- c(&quot;sample_8765&quot;,&quot;sample_8901&quot;,&quot;sample_9084&quot;) #unique samples 
  
  #seperating by type
  samples &lt;- bind_rows(mget(paste0(sample_ID)), .id = &quot;Sample_ID&quot;) %&gt;%
              split(.$type) 
  mRNA_samples &lt;- samples$mRNA 
  
  mRNAs &lt;- unique(mRNA_samples$name) #unique mRNAs 
  
  
  #creating empty matrix
  mRNA_df &lt;- matrix(nrow = 4, ncol = 3)
  rownames(mRNA_df) = mRNAs
  colnames(mRNA_df) = sample_ID
  
  </code></pre>
  <p>The output that I would like to see is something like this!</p>
  <pre><code>#       sample_8765   sample_8901   sample_9084
  #X1345  4.265          5.33           4.35
  #X1234  3.44           0              9.11
  #F1234  6.43           0              0
  #F4657  0              6.78           6.78
  </code></pre>