if statement - Fast way to figure out if a number is inside a vector in R -
i hoping figure out fast way find out if number contained within vector purpose of passing if statement. far, best have come following:
a = 5 b = 1:10 if(length(which(a==5)) > 0){ #do something... }
i'm sure there faster way of doing this.
use %in%
:
if (a %in% b) ...
this may not faster you've got (since it's syntactic sugar match
call) it's more compact , transparent.
Comments
Post a Comment