1

I would like to find the minimum value a of vector but without including certain value

ex :

a <- c(1, 2, 3, 4, 5 ,-9999 ,7 ,8 ,9)

And I want to avoid values 1 and -9999. So the answer here would be 2.

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
jo.H
  • 59
  • 4

1 Answers1

1

We can use setdiff to include only those elements which we want and find the minimum among them.

min(setdiff(a, ignore))
#[1] 2

data

a <- c(1, 2, 3, 4, 5 ,-9999 ,7 ,8 ,9)
ignore <- c(1, -9999)
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213