fancycut

January 8, 2017
By

(This article was first published on TeachR, and kindly contributed to R-bloggers)

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

fancycut(
  x = -10:10,
  SubZero = '(-Inf,0)',
  Zero = '[0,0]',
  Small = '(0,2]',
  Medium = '(2,5)',
  Large = '[5,10]',
  out.as.factor = FALSE
)

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.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Sponsors

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)