r - Find the minimum of a vector ignoring certain numbers -


this question has answer here:

i find minimum value of vector without including value

ex :

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

and want avoid values 1 , -9999. answer here 2.

we can use setdiff include elements want , find 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) 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -