[R] Quick question: Omitting rows and cols with certain percents of missing values

Peter Ehlers ehlers at ucalgary.ca
Fri May 13 16:43:59 CEST 2011


On 2011-05-13 06:42, Vickie S wrote:
>
> Hi
> naive question.
> It is possible to get R command for omitting rows or cols with missing values present.
>
> But
> if i want to omit rows or cols with i.e .>20% missing values, I
> could´t find any package-based command, probably because it is too
> simple for anyone to do that manually, though not for me. Can anyone
> please help me ?

Example:

  set.seed(2718)
  m <- matrix(sample(1:9, 100, TRUE), 10, 10)
  is.na(m) <- sample(100, 20)
  d <- as.data.frame(m)
  d[rowSums(is.na(d)) / nrow(d) <= 0.2,]
  d[colSums(is.na(d)) / ncol(d) <= 0.2,]


Peter Ehlers



More information about the R-help mailing list