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 !!
question from:
https://stackoverflow.com/questions/9265553/r-filter-a-vector-using-a-function 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…