freqs: Frequencies Calculations and Plot

View source: R/frequencies.R

freqsR Documentation

Frequencies Calculations and Plot

Description

This function lets the user group, count, calculate percentages and cumulatives. It also plots results if needed. Tidyverse friendly.

Usage

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
)

Arguments

df

Data.frame

...

Variables. Variables you wish to process. Order matters. If no variables are passed, the whole data.frame will be considered

wt

Variable, numeric. Weights.

rel

Boolean. Relative percentages (or absolute)?

results

Boolean. Return results in a dataframe?

variable_name

Character. Overwrite the main variable's name

plot

Boolean. Do you want to see a plot? Three variables tops.

rm.na

Boolean. Remove NA values in the plot? (not filtered for numerical output; use na.omit() or filter() if needed)

title

Character. Overwrite plot's title with.

subtitle

Character. Overwrite plot's subtitle with.

top

Integer. Filter and plot the most n frequent for categorical values. Set to NA to return all values

abc

Boolean. Do you wish to sort by alphabetical order?

save

Boolean. Save the output plot in our working directory

subdir

Character. Into which subdirectory do you wish to save the plot to?

Value

Plot when plot=TRUE and data.frame with grouped frequency results when plot=FALSE.

See Also

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()

Other Visualization: distr(), freqs_df(), freqs_list(), freqs_plot(), noPlot(), plot_chord(), plot_survey(), plot_timeline(), tree_var()

Examples

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)

lares documentation built on Sept. 13, 2024, 1:08 a.m.