dt_na_breakdown: Get a breakdown of the NA-status of a column in a data.table

dt_na_breakdownR Documentation

Get a breakdown of the NA-status of a column in a data.table

Description

This function takes a (quoted) column to group by, and tabulates the count of how many of those values are not-NA and NA, and adds the percent of occurrences. A TRUE in the first output column means the data is _not_ missing; FALSE corresponds to missing.

Usage

dt_na_breakdown(DT, acolumn, big.mark = FALSE)

Arguments

DT

The data.table object to operate on

acolumn

a quoted column name

big.mark

If FALSE (default) the "count" column is left as an integer. If not FALSE, it must be a character to separate every three digits of the count. This turns the count column into a string.

Details

The final row is a total count

The quoted group-by variable must be a character or factor

Value

Returns a data.table with three columns: the not-NA status of the column specified, a count column, and a percent column (out of 100) to two decimal places

Examples


iris_dt <- as.data.table(iris)
iris_dt[sample(1:.N, 10), Species:=NA_character_]
dt_na_breakdown(iris_dt, "Species")


libbib documentation built on Nov. 10, 2022, 6:16 p.m.