gen_group: make a group column for a tibble

Description Usage Arguments Value Examples

View source: R/grouping.R

Description

make a group column for a tibble

Usage

1
gen_group(data, id_col, group_by_col, group_method = "category", ...)

Arguments

data

a tibble data set

id_col

the id column of the data set for grouping

group_by_col

the column used for grouping

group_method

the grouping methods include "category", "equal_interval", "equal_number", "cut_by_breaks", and "percent_rank", which utilize some functions provided by ggplot2 and dplyr.

...

Arguments passed on to different group_method. For the method "cut_by_breaks", breaks must be provided. The variable "labels" are commonly used by the "equal_interval", "equal_number", and "cut_by_breaks".

Value

A tibble containing id_col and group column.

Examples

1
2
3
4
5
6
7
8
9
  data = iris %>% mutate(id = str_c("id_", 1:nrow(.)))
  gen_group(data = data, id_col = "id", group_by_col = "Species", group_method = "category")
  gen_group(data = data, id_col = "id", group_by_col = "Sepal.Length",
           group_method = "equal_interval", labels = c("low", "middle", "high"))
  gen_group(data = data, id_col = "id", group_by_col = "Sepal.Length",
           group_method = "equal_number", labels = c("low", "middle", "high"))
  gen_group(data = data, id_col = "id", group_by_col = "Sepal.Length",
           group_method = "cut_by_breaks", breaks = c(0, 5.1, 6.5, 100), labels = c("low", "middle", "high"))
  gen_group(data = data, id_col = "id", group_by_col = "Sepal.Length", group_method = "percent_rank")

yuehmeir2/CATSimulator documentation built on June 13, 2021, 7:02 p.m.