
Last chance! 50% off unlimited learning
Sale ends in
This function lets the user group, count, calculate percentages and cumulatives. It also plots results if needed. Tidyverse friendly.
freqs(
df,
...,
wt = NULL,
rel = FALSE,
results = TRUE,
variable_name = NA,
plot = FALSE,
rm.na = FALSE,
title = NA,
subtitle = NA,
top = 20,
abc = FALSE,
save = FALSE,
subdir = NA
)
Data.frame
Variables. Variables you wish to process. Order matters. If no variables are passed, the whole data.frame will be considered
Variable, numeric. Weights.
Boolean. Relative percentages (or absolute)?
Boolean. Return results in a dataframe?
Character. Overwrite the main variable's name
Boolean. Do you want to see a plot? Three variables tops.
Boolean. Remove NA values in the plot? (not filtered for numerical output; use na.omit() or filter() if needed)
Character. Overwrite plot's title with.
Character. Overwrite plot's subtitle with.
Integer. Filter and plot the most n frequent for categorical values. Set to NA to return all values
Boolean. Do you wish to sort by alphabetical order?
Boolean. Save the output plot in our working directory
Character. Into which subdirectory do you wish to save the plot to?
Plot when plot=TRUE
and data.frame with grouped frequency results
when plot=FALSE
.
Other Frequency:
freqs_df()
,
freqs_list()
,
freqs_plot()
Other Exploratory:
corr_cross()
,
corr_var()
,
crosstab()
,
df_str()
,
distr()
,
freqs_df()
,
freqs_list()
,
freqs_plot()
,
lasso_vars()
,
missingness()
,
plot_cats()
,
plot_df()
,
plot_nums()
,
tree_var()
,
trendsRelated()
Other Visualization:
distr()
,
freqs_df()
,
freqs_list()
,
freqs_plot()
,
noPlot()
,
plot_chord()
,
plot_survey()
,
plot_timeline()
,
tree_var()
# NOT RUN {
Sys.unsetenv("LARES_FONT") # Temporal
data(dft) # Titanic dataset
# How many survived?
dft %>% freqs(Survived)
# How many survived per Class?
dft %>% freqs(Pclass, Survived, abc = TRUE)
# How many survived per Class with relative percentages?
dft %>% freqs(Pclass, Survived, abc = TRUE, rel = TRUE)
# Using a weighted feature
dft %>% freqs(Pclass, Survived, wt = Fare / 100)
# Let's check the results with plots:
#' # How many survived and see plot?
dft %>% freqs(Survived, plot = TRUE)
# How many survived per class?
dft %>% freqs(Survived, Pclass, plot = TRUE)
# Per class, how many survived?
dft %>% freqs(Pclass, Survived, plot = TRUE)
# Per sex and class, how many survived?
dft %>% freqs(Sex, Pclass, Survived, plot = TRUE)
# Frequency of tickets + Survived
dft %>% freqs(Survived, Ticket, plot = TRUE)
# Frequency of tickets: top 10 only and order them alphabetically
dft %>% freqs(Ticket, plot = TRUE, top = 10, abc = TRUE)
# }
Run the code above in your browser using DataLab