title: creating a subset of data frame when running a loop
body: <p>I'm quite new in R, trying to find my why around. I have created a new data frame based on the "original" data frame. </p>
  
  <pre><code>library(dplyr)
  prdgrp &lt;- as.vector(mth['MMITCL'])
  prdgrp %&gt;% distinct(MMITCL)
  </code></pre>
  
  <p>When doing this, then the result is a list of Unique values of the column MMITCL. I would like to use this data in a loop sequence that first creates a new subset of the original data and the prints a graph based on this:</p>
  
  <pre><code>#START LOOP
  for (i in 1:length(prdgrp))
  {
  # mth[c(MMITCL==prdgrp[i],]
  mth_1 &lt;- mth[c(mth$MMITCL==prdgrp[i]),]
  # Development of TPC by month 
  library(ggplot2)
  library(scales)
  ggplot(mth_1, aes(Date, TPC_MTD))+ geom_line()
  }
  # END LOOP
  </code></pre>
  
  <p>Doing this gives me the following error message:</p>
  
  <pre><code>Error in mth$MMITCL == prdgrp[i] : 
    comparison of these types is not implemented
  In addition: Warning:
  I `[.data.frame`(mth, c(mth$MMITCL == prdgrp[i]), ) :
    Incompatible methods ("Ops.factor", "Ops.data.frame") for "=="
  </code></pre>
  
  <p>What am I doing wrong.</p>