title: Collapsing categorieal levels R
body: <p>I have data (s_data).</p>
  <pre><code>levels(as.factor(s_data$education))
  
  &quot;10th&quot;          &quot;11th&quot;         &quot;12th&quot;         &quot;1st-4th&quot;     
  &quot;5th-6th&quot;      &quot;7th-8th&quot;      &quot;9th&quot;          &quot;Assoc-acdm&quot;    
  &quot;Assoc-voc&quot;    &quot;Bachelors&quot;    &quot;Doctorate&quot;    &quot;HS-grad&quot;     
  &quot;Masters&quot;      &quot;Preschool&quot;    &quot;Prof-school&quot;  &quot;Some-college&quot;
  </code></pre>
  <p>I am trying to collapse samples into one category. For example, &quot;Preschool&quot; and &quot;1st-4th&quot; would be one category, kids.  I have tried a couple of approaches with no success.</p>
  <pre><code>s_data$education &lt;- case_when(data$education %in% c(&quot;1st-4th&quot;, &quot;5th-6th&quot;, &quot;7th-8th&quot;,
                                        &quot;9th&quot;,&quot;Preschool&quot;) ~ &quot;kids&quot;) #s_data is an adjusted version of data
  </code></pre>
  <p>This approach tries to replace each row and doesn't yield anything but an error.</p>
  <p>I have tried our teacher's approach and when I tried to plot the new data, it did not consist the new category (&quot;kids&quot;) at all.</p>
  <pre><code>levels(as.factor(s_data$education)) &lt;- c(&quot;10th&quot;,&quot;11th,&quot;, &quot;kids&quot;, &quot;kids&quot;, &quot;kids&quot;,&quot;7th-8th&quot;, &quot;9th&quot;, &quot;Assoc-acdm&quot;,
                                           &quot;Assoc-voc&quot;, &quot;Bachelors&quot;,&quot;Doctorate&quot;,&quot;HS-grad&quot;, &quot;Masters&quot;,&quot;kids&quot;, &quot;Prof-school&quot;,
                                           &quot;Some-college&quot;)
  </code></pre>
  <p>Do you have ideas how can I collapse these levels into one category?</p>
  <p>Thank you!</p>