R !!!欠損値 {{outline}} !欠損値を見つける <> {{pre [82,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [83,] FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [84,] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE }} {{pre subset(データフレーム, is.na(カラム名) ) }} * これで、カラムで空欄になっている行が見つけられる。 !欠損値があるか確認 <> {{pre > anyNA(JPNindexTopic) [1] TRUE }} !欠損値の数を数える {{pre > sum(is.na(cor2.1st$ipsyn.25)) [1] 30 > table(is.na(cor2.1st$ipsyn.25)) FALSE TRUE 49 30 }} !欠損値を除く <> {{pre > df.ns.nns.bigram bigram freq.x freq.y 1 of the 400 300 2 in the 200 30 3 at the 100 NA 4 you know 50 200 5 i know 25 20 6 i think NA 250 > na.omit(df.ns.nns.bigram) bigram freq.x freq.y 1 of the 400 300 2 in the 200 30 4 you know 50 200 5 i know 25 20 }} !欠損値を無視するオプション na.rm = TRUE !欠損値を 0 に置き換える {{pre > zero bigram freq.x freq.y 1 of the 400 300 2 in the 200 30 3 at the 100 NA 4 you know 50 200 5 i know 25 20 6 i think NA 250 > zero[is.na(zero)] <- 0 > zero bigram freq.x freq.y 1 of the 400 300 2 in the 200 30 3 at the 100 0 4 you know 50 200 5 i know 25 20 6 i think 0 250 }} *reference https://www.pediatricsurgery.site/entry/2017/07/07/232423 !!欠損値の補完 !時系列データの場合 *前後の値の平均を使う !独立データの場合 *欠損値を除いた全体の平均を使う !Reference http://www.okadajp.org/RWiki/?R%E3%81%A7%E3%83%87%E3%83%BC%E3%82%BF%E3%82%AF%E3%83%AA%E3%83%BC%E3%83%8B%E3%83%B3%E3%82%B0#d37b212d