Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

export(MultivariateOutlier)
export(Outlier)
export(SummaryStatsCat)
export(SummaryStatsNum)
export(Summary)
export(autoCorrelationPlot)
export(autoDensityPlot)
export(autoDensityPlot_)
Expand Down
33 changes: 30 additions & 3 deletions R/SummaryFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' mean, SD, SE, median, min, max, range, skew and kurtosis) for a specified numerical variable
#' @param x = variable
#' @return vector with summary statistics
#' @export


SummaryStatsNum <- function(x) {

Expand All @@ -20,7 +20,7 @@ SummaryStatsNum <- function(x) {
median <- median(x)
min <- min(x)
max <- max(x)
range <- range(x)
range <- max - min
skew <- psych::skew(x)
kurtosis <- psych::kurtosi(x)

Expand All @@ -32,7 +32,7 @@ SummaryStatsNum <- function(x) {
#' @description This function will return summary statistics (counts, percentage, missing values) for a specified categorical variable
#' @param x = variable
#' @return Data frame with summary statistics (count and percentage) for each level of the categorical variable
#' @export


SummaryStatsCat <- function(x){

Expand All @@ -45,3 +45,30 @@ SummaryStatsCat <- function(x){

data.frame(count, percentage)
}

#' Summary function for both categorical and numerical variables
#' @description This function will return relevant summary statistics dependent on the data type of the variable inputted
#' @param x A variable of type categorical or numerical
#' @return Data frame with relevant summary statistics

VSummary <- function(x){
class <- class(x)
switch(class,
numeric = data.frame(SummaryStatsNum(x)),
factor = data.frame(SummaryStatsCat(x)),
stop("x is not a data type numeric or factor", call. = FALSE))
}

#' Summary function that takes in a data frame or vector of categorical or numerical varibales and provides summary statistics
#' @description This function will provide relevant summary statistics for inputted data frames or vectors of categorrical or numerical variables
#' @param object can be a data frame or vector
#' @return Data frame with relevant summary statistics
#' @export

Summary <- function(object){
if (class(object) == "data.frame"){
lapply(object, VSummary)
} else{
data.frame(VSummary(object))
}
}
17 changes: 17 additions & 0 deletions man/Summary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/VSummary.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.