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
11 changes: 8 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ Package: tricks
Title: Performs statistical tricks
Version: 0.0.0.9000
Authors@R:
person(given = "Travis",
c(person(given = "Travis",
family = "Gerke",
role = c("aut", "cre"),
email = "travis.gerke@moffitt.org")
email = "travis.gerke@moffitt.org"),
person("Garrick",
"Aden-Buie",
email = "garrick.aden-buie@moffitt.org"))
Description: What the package does (one paragraph)
License: What license it uses
Encoding: UTF-8
Expand All @@ -18,6 +21,8 @@ Suggests:
Language: en-US
Imports:
magrittr,
broom
broom,
purrr,
dplyr
URL: https://github.com/GerkeLab/tricks
BugReports: https://github.com/GerkeLab/tricks/issues
8 changes: 6 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Generated by roxygen2: fake comment so roxygen2 overwrites silently.
exportPattern("^[^\\.]")
# Generated by roxygen2: do not edit by hand

export("%>%")
export(pre_sort)
export(sorting_hat)
importFrom(magrittr,"%>%")
32 changes: 32 additions & 0 deletions R/sorting_hat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' Gather information about the data variables
#'
#' @param df The input data frame
#' @export
sorting_hat <- function(df) {
x <- purrr::map(df, class) %>%
purrr::map_dfr(~ data.frame(type = ., stringsAsFactors = FALSE), .id = "col_name") %>%
dplyr::mutate(
n_unique = purrr::map_int(df, ~ length(unique(.))),
n_complete = purrr::map_int(df, ~ length(.x[!is.na(.x)]))
)

x$cv <- purrr::map_dbl(x$col_name, ~ cov(df[[.]]))

x
}

cov <- function(x) {
if (!inherits(x, "numeric")) return(NA_real_)
sd(x, TRUE)/mean(x, na.rm = TRUE)
}

#' Pre-sorting processing of data
#'
#' Cast character columns to factors.
#'
#' @param df The input data frame
#' @export
pre_sort <- function(df) {
df %>%
dplyr::mutate_if(is.character, as.factor)
}
12 changes: 12 additions & 0 deletions man/pipe.Rd

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

14 changes: 14 additions & 0 deletions man/pre_sort.Rd

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

14 changes: 14 additions & 0 deletions man/sorting_hat.Rd

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