描述

    计算一个或多个变量的唯一值

    Usage

    count_dt(.data, …, sort = TRUE, .name = “n”)

    add_count_dt(.data, …, .name = “n”)

    Arguments

    .data data.table/data.frame data.frame will be automatically converted to data.table.

    … Variables to group by, could receive what ‘select_dt‘ receives.

    sort logical. If TRUE result will be sorted in desending order by resulting variable.

    .name character. Name of resulting variable. Default uses “n”.

    Value

    data.table

    1. iris %>% count_dt(Species)
    2. iris %>% count_dt(Species,.name = "count")
    3. iris %>% add_count_dt(Species)
    4. iris %>% add_count_dt(Species,.name = "N")
    5. mtcars %>% count_dt(cyl,vs)
    6. mtcars %>% count_dt(cyl,vs,.name = "N",sort = FALSE)
    7. mtcars %>% add_count_dt(cyl,vs)