I have a function similar to this one:
isGoodNumber <- function(X)
{
if (X==5) return(TRUE) else return(FALSE)
}
I have a vector:
v<-c(1,2,3,4,5,5,5,5)
I want to obtain a new vector that contains the elements of v where isGoodNumber(v) == TRUE
How do I do this ?
Tried v [ isGoodNumber(v) == TRUE ] but it doesn’t work 🙂
Thanks !!
You’ll need to Vectorize the function to call it on a vector: