Skip to content

Commit

Permalink
get_prop() function is added
Browse files Browse the repository at this point in the history
  • Loading branch information
seokhoonj committed Aug 9, 2024
1 parent cf4330d commit c652a70
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export(get_japanese_cols)
export(get_labels)
export(get_pattern)
export(get_pattern_all)
export(get_prop)
export(get_ptr)
export(get_stat_by)
export(grepl_and)
Expand Down
20 changes: 20 additions & 0 deletions R/group.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,23 @@ get_stat_by <- function(df, group_var, value_var, fun = sum) {
# data.table::setattr(df, "class", old_class)
return(dt)
}

#' Get proportion from a vector
#'
#' Get proportion from a vector.
#'
#' @param x a vector
#' @return a proportion data.frame
#'
#' @examples
#' \dontrun{
#' get_prop(sample(1:10, 1000, replace = TRUE))}
#'
#' @export
get_prop <- function(x) {
op <- options(scipen = 14)
df <- data.table::as.data.table(prop.table(table(x)))
set_col_lower(df)
on.exit(op)
return(df)
}
22 changes: 22 additions & 0 deletions man/get_prop.Rd

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

0 comments on commit c652a70

Please sign in to comment.