How to Use The Cut Function In R Programming
Basic subset functions in R provide ways to categorize your data. Here is a simple function for identifying ranges that your data fits into.
Cut() is an often overlooked R programming function that is used for creating subsets within a list of R programming object elements. The subsets are bins — a range that you set for convenience.
Cut() differs from the slice() function in the dyplr library. Slice subsets according to the observations, and can even insert functions that determine where the subsets should occur. With the cut() function, you are actually positioning and naming where the bins should occur without requiring a calculation — just the range of numbers you want.
As an example, I am taking the data set GT cars from the GT library, and inserting them into an object in R as a data frame. I plan on creating bins based on miles per gallon rating of the listed vehicles. Below is the dataset — I included a view of the set so you can see the mpg_c column from which the data will be created.