title: Converting data frame to tibble with word count
body: <p>I'm attempting to perform sentiment analysis based on <a href="http://tidytextmining.com/sentiment.html#the-sentiments-dataset" rel="nofollow noreferrer">http://tidytextmining.com/sentiment.html#the-sentiments-dataset</a> . Prior to performing sentiment analysis I need to convert my dataset into a tidy format.</p>
  
  <p>my dataset is of form : </p>
  
  <pre><code>x &lt;- c( "test1" , "test2")
  y &lt;- c( "this is test text1" , "this is test text2")
  res &lt;- data.frame( "url" = x, "text" = y)
  res
      url               text
  1 test1 this is test text1
  2 test2 this is test text2
  </code></pre>
  
  <p>In order to convert to one observation per row require to process text column and add new columns that contains word and number of times it appears for that url. Same url will appear in multiple rows.</p>
  
  <p>Here is my attempt  : </p>
  
  <pre><code>library(tidyverse)
  
  x &lt;- c( "test1" , "test2")
  y &lt;- c( "this is test text1" , "this is test text2")
  res &lt;- data.frame( "url" = x, "text" = y)
  res
  
  res_1 &lt;- data.frame(res$text)
  res_2 &lt;- as_tibble(res_1)
  res_2 %&gt;% count(res.text, sort = TRUE) 
  </code></pre>
  
  <p>which returns : </p>
  
  <pre><code># A tibble: 2 x 2
              res.text     n
                &lt;fctr&gt; &lt;int&gt;
  1 this is test text1     1
  2 this is test text2     1
  </code></pre>
  
  <p>How to count words in res$text dataframe and maintain url in order to perform sentiment analysis ?</p>
  
  <p>Update : </p>
  
  <pre><code>x &lt;- c( "test1" , "test2")
  y &lt;- c( "this is test text1" , "this is test text2")
  res &lt;- data.frame( "url" = x, "text" = y)
  res
  
  res %&gt;%
  group_by(url) %&gt;%
  transform(text = strsplit(text, " ", fixed = TRUE)) %&gt;%
  unnest() %&gt;%
  count(url, text) 
  </code></pre>
  
  <p>returns error  :</p>
  
  <pre><code>Error in strsplit(text, " ", fixed = TRUE) : non-character argument
  </code></pre>
  
  <p>I'm attempting to convert to tibble as this appears to be format required for tidytextmining sentiment analysis : <a href="http://tidytextmining.com/sentiment.html#the-sentiments-dataset" rel="nofollow noreferrer">http://tidytextmining.com/sentiment.html#the-sentiments-dataset</a> </p>