欠損値はいくつありますか?
新しいデータセットで最初に確認したいことのひとつは、欠損値があるかどうか、そしていくつあるかです。
are_na() を使って欠損値を数えることもできますが、欠損を数える最も効率的な方法は n_miss() 関数を使うことです。これにより、データ内の欠損値の合計数がわかります。
次に、pct_miss 関数を使うとデータ内の欠損値の割合を求められます。これは、データにおける欠損値のパーセンテージを示します。
さらに、これらの補集合として、n_complete と pct_complete を使うと、完全な値がいくつあるか、その割合も求められます。
この演習はコースの一部です
Rでの欠損データの扱い方
演習の手順
身長と体重の例データフレーム dat_hw を使って、次を行ってください。
- データフレーム
dat_hwにn_miss()を使い、データフレーム内の欠損値の合計数を数えます。 - 変数
dat_hw$weightにn_miss()を使い、その変数内の欠損値の合計数を数えます。 - 同様に、
prop_miss()、n_complete()、prop_complete()を使って、欠損の割合、そしてデータフレームおよび各変数における完全な値の数と割合を取得します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Use n_miss() to count the total number of missing values in dat_hw
n_miss(___)
# Use n_miss() on dat_hw$weight to count the total number of missing values
n_miss(___$___)
# Use n_complete() on dat_hw to count the total number of complete values
n_complete(___)
# Use n_complete() on dat_hw$weight to count the total number of complete values
___(___$___)
# Use prop_miss() and prop_complete() on dat_hw to count the total number of missing values in each of the variables
prop_miss(____)
prop_complete(___)