na_in_row: Count/proportion of 'NA's and not-'NA's per dataframe row

View source: R/dataframe_tools.R

na_in_rowR Documentation

Count/proportion of NAs and not-NAs per dataframe row

Description

Count/proportion of NAs and not-NAs per dataframe row

Usage

na_in_row(df, ...)

Arguments

df

(Dataframe) A dataframe.

...

(Tidy-select) dplyr-style column selection. See dplyr::dplyr_tidy_select(). If empty, defaults to dplyr::everything().

Value

The dataframe df with four new columns: na_in_row_count, notna_in_row_count, na_in_row_prop, and notna_in_row_prop.

Source

Authors

Examples

df <- data.frame(a = c(1, 2, NA, 4, NA), b = 1:5, c = c(NA, 2, 3, NA, NA))

df

#>     a b  c
#> 1   1 1 NA
#> 2   2 2  2
#> 3  NA 3  3
#> 4   4 4 NA
#> 5  NA 5 NA

# By default, looks for NAs in all columns
na_in_row(df)

#    a b  c na_in_row_count notna_in_row_count na_in_row_prop notna_in_row_prop
# 1  1 1 NA               1                  2      0.3333333         0.6666667
# 2  2 2  2               0                  3      0.0000000         1.0000000
# 3 NA 3  3               1                  2      0.3333333         0.6666667
# 4  4 4 NA               1                  2      0.3333333         0.6666667
# 5 NA 5 NA               2                  1      0.6666667         0.3333333

# Or use tidyselectors to choose columns. Here, looking for 
# NAs in all columns except `b`
na_in_row(df, -b)

#    a b  c na_in_row_count notna_in_row_count na_in_row_prop notna_in_row_prop
# 1  1 1 NA               1                  1            0.5               0.5
# 2  2 2  2               0                  2            0.0               1.0
# 3 NA 3  3               1                  1            0.5               0.5
# 4  4 4 NA               1                  1            0.5               0.5
# 5 NA 5 NA               2                  0            1.0               0.0


DesiQuintans/desiderata documentation built on April 9, 2023, 5:43 a.m.