fn_freq {Morefi}
20 May 2024
fn_freq.Rmd
Frequency distribution
Description
The function fn_freq
calculates a frequency distribution
of data using the functions: cut()
and table()
from the R base.
Inside the function: The non-cumulative absolute frequency is
calculated for each user-defined class interval within the
breaks
object.
The breaks
object must be defined outside the function
by the user. For example a sequence of breakpoints of equal distance
could be used.
A table with frequencies by class interval is returned.
The function requires defining:
-
df: A vector of data values.
- breaks: A vector with class intervals.
- right: Logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa.
fn_freq
The function is included in the Morefi
package
Morphological Relationships Fitted by Robust
Regression.
The function is detailed below.
Examples
In the “df” object, 30 random values between 0.1 and 0.9 are generated. The breaks object is a sequence of equal distances.
df <- runif(n=30, min=0, max=1)
breaks <- seq(0, 1, by= 0.1)
freq <- fn_freq(df, breaks, right= FALSE)
freq
fcut [0,0.1) [0.1,0.2) [0.2,0.3) [0.3,0.4) [0.4,0.5) [0.5,0.6) [0.6,0.7) [0.7,0.8) 5 4 2 2 4 1 4 4 [0.8,0.9) [0.9,1) 2 2
References
Yau C (2024, deck 25). Frequency Distribution of Quantitative Data. R Tutorial An R Introduction to Statistics. https://www.r-tutor.com/elementary-statistics/quantitative-data/frequency-distribution-quantitative-data