View source: R/dataframe_tools.R
na_in_row | R Documentation |
NA
s and not-NA
s per dataframe rowCount/proportion of NA
s and not-NA
s per dataframe row
na_in_row(df, ...)
df |
(Dataframe) A dataframe. |
... |
(Tidy-select) |
The dataframe df
with four new columns: na_in_row_count
, notna_in_row_count
,
na_in_row_prop
, and notna_in_row_prop
.
Desi Quintans (http://www.desiquintans.com)
maloneypatr (https://stackoverflow.com/users/2124146/maloneypatr)
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.