RosettaCodeData/Task/Search-a-list/R/search-a-list-1.r
Ingy döt Net 86c034bb8b new files
2013-04-10 12:38:42 -07:00

6 lines
249 B
R

find.needle <- function(haystack, needle="needle", return.last.index.too=FALSE)
{
indices <- which(haystack %in% needle)
if(length(indices)==0) stop("no needles in the haystack")
if(return.last.index.too) range(indices) else min(indices)
}