LoginSignup
4
6

More than 5 years have passed since last update.

【R】1つでも欠損値のある行のみを取り出す

Last updated at Posted at 2015-09-17

data.frameから1つでも欠損値のある行を取り出す。
使うことはあまりないが忘れた時のために…。

# sample data
dat <- data.frame(
  a = c(1, 1, NA, 0, 1),
  b = c(NA, 0, 1, NA, 0),
  c = c(NA, 0, 1, 1, 0)
)

# 1つでも欠損値(NA)をもつ行を取り出す
dat[!complete.cases(dat), ]

# !を除くとna.omit(dat)と同じく欠損値をもつ行を取り除く
dat[complete.cases(dat), ]

4
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
6