formattedcut | R Documentation |
Often, when a continuous data is converted to factors using the base R
cut function, the resultant Class Interval
column provide data with
scientific notation which normally appears confusing to interpret,
especially to casual data scientist. This function provide a more
user-friendly output and is provided in a formatted manner. It is a easy to
implement function.
formattedcut(data, breaks, cut = FALSE)
data |
A vector of the data to be converted to factors if not cut already or the vector of a cut data |
breaks |
Number of classes to break the data into |
cut |
|
The function returns a data frame
with three or four columns
i.e Lower class
, Upper class
, Class interval
and Frequency
(if the
cut is FALSE
).
Cut |
The |
library(tidyverse)
DD <- rnorm(100000)
formattedcut(DD, 12, FALSE)
DD1 <- cut(DD, 12)
DDK <- formattedcut(DD1, 12, TRUE)
DDK
# if data is not from a data frame, the frequency distribution is required.
as.data.frame(DDK %>%
group_by(`Lower class`, `Upper class`, `Class interval`) %>%
tally())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.