[This article was first published on TeachR, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

An updated version of my package fancycut is on CRAN. The package has one function, fancycut(), that is more versatile than cut() for certain applications. cut() takes a numeric vector and turns it into a factor or categorical vector. It works best when they are no gaps in the intervals you have defined and when the are all either right handed or left handed. It does not like point intervals or mixed open, closed, etc. fancycut() is OK with all of this. It uses interval notation we learned in high school math which is why I like it. Here is an example

<span class="n">fancycut</span><span class="p">(</span><span class="w">
  </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="m">-10</span><span class="o">:</span><span class="m">10</span><span class="p">,</span><span class="w">  
  </span><span class="n">SubZero</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'(-Inf,0)'</span><span class="p">,</span><span class="w">  
  </span><span class="n">Zero</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'[0,0]'</span><span class="p">,</span><span class="w">  
  </span><span class="n">Small</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'(0,2]'</span><span class="p">,</span><span class="w">  
  </span><span class="n">Medium</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'(2,5)'</span><span class="p">,</span><span class="w">  
  </span><span class="n">Large</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'[5,10]'</span><span class="p">,</span><span class="w">  
  </span><span class="n"></span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">FALSE</span><span class="w">  
</span><span class="p">)</span><span class="w">  

This returns

[1] 'SubZero' 'SubZero' 'SubZero' 'SubZero' 'SubZero' 'SubZero' 'SubZero' 'SubZero' 'SubZero' 'SubZero' 'Zero'    'Small'   'Small'   'Medium'  'Medium' 
[16] 'Large'   'Large'   'Large'   'Large'   'Large'   'Large'

It has other features, too, please see the help files.

To leave a comment for the author, please follow the link and comment on their blog: TeachR. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)