title: How to count total character occurence in data frame and add column using mutate in R
body: <p>I have a data frame (<code>dat</code>) with a column having sequence (<code>Seq</code>) (character class). I am trying to split the sequence in each row and count the numbers of <code>'A'</code>, <code>'C'</code>, <code>'G'</code>, <code>'T'</code> and add each column using mutate (in <code>dplyr</code>). Below is my sample data frame and code I am trying.</p>
  
  <pre><code>   Seq
  CAGGACATAA
  TGTCCACTGC
  </code></pre>
  
  <p>Code I am trying to execute:</p>
  
  <pre><code>count_bases &lt;- function (x){
      for(i in 1:length(x)){
          tab[i] &lt;- table(strsplit((x)[i],""))
      }
      return(tab)
  }
  count_bases(dat$Seq)
  </code></pre>
  
  <p>If I just use for first row the command: <code>table(strsplit(dat$Seq[1],""))</code> it works fine and gives me the result. Desired output which I am trying to get is by above function and mutate to create a data frame shown below:</p>
  
  <pre><code>    Seq    A C G T
  CAGGACATAA 5 2 2 1
  TGTCCACTGC 1 4 2 3
  </code></pre>