title: get the number of character vector elements in a corpus
body: <p>my goal is to use R for lexicon based sentiment analysis!</p>
  
  <p>i have two character vectors. one with positive words and one with negative words.
  e.g. </p>
  
  <pre><code>pos &lt;- c("good", "accomplished", "won", "happy")
  neg &lt;- c("bad", "loss", "damaged", "sued", "disaster")
  </code></pre>
  
  <p>i now have a corpus of thousands of news articles and i want to know for each article, how
  many elements of my vectors pos and neg are in the article.</p>
  
  <p>e.g. (not sure about how the corpus function works here but you get the idea: there are two articles in my corpus)</p>
  
  <pre><code>mycorpus &lt;- Corpus("The CEO is happy that they finally won the case.", "The disaster caused a huge loss.")
  </code></pre>
  
  <p>i want to get something like this:</p>
  
  <pre><code>article 1: 2 element of pos and 0 element of neg
  article 2: 0 elements of pos, 2 elements of neg
  </code></pre>
  
  <p>another good thing would be, if i can get the following for each article:</p>
  
  <p>(number of pos words - number of neg words)/(number of total words in article)</p>
  
  <p>thank you very much!!</p>
  
  <p>EDIT:</p>
  
  <p>@ Victorp: this doesn't seem to work</p>
  
  <p>the matrix i get looks good:</p>
  
  <pre><code>mytdm[1:6,1:10]
                 Docs
  Terms          1 2 3 4 5 6 7 8 9 10
  aaron          0 0 0 0 0 1 0 0 0  0
  abandon        1 1 0 0 0 0 0 0 0  0
  abandoned      0 0 0 3 0 0 0 0 0  0
  abbey          0 0 0 0 0 0 0 0 0  0
  abbott         0 0 0 0 0 0 0 0 0  0
  abbotts        0 0 1 0 0 0 0 0 0  0
  </code></pre>
  
  <p>but when i do your command i get zero for every document!</p>
  
  <pre><code>colSums(mytdm[rownames(mytdm) %in% pos, ])
     1    2    3    4    5    6    7    8    9   10   11   12   13   14   15 
     0    0    0    0    0    0    0    0    0    0    0    0    0    0    0 
    16   17   18   19   20   21   22   23   24   25   26   27   28   29   30 
     0    0    0    0    0    0    0    0    0    0    0    0    0    0    0
  </code></pre>
  
  <p>why is that??</p>