Skip to content

Instantly share code, notes, and snippets.

@JoFrhwld
Created April 26, 2013 19:09
Show Gist options
  • Save JoFrhwld/5469628 to your computer and use it in GitHub Desktop.
Save JoFrhwld/5469628 to your computer and use it in GitHub Desktop.
multi_match <- function(x, table){
# returns initial indicies of all substrings in table which match x
if(length(table) < length(x)){
return(NA)
}else{
check_mat <- matrix(nrow = length(x), ncol = length(table))
for(i in 1:length(x)){
check_mat[i,] <- table %in% x[i]
}
out <- vector(length = length(table))
for(i in 1:(length(table)-(length(x)-1))){
check <- vector(length=length(x))
for(j in 1:length(x)){
check[j] <- check_mat[j,(i+(j-1))]
}
out[i] <- all(check)
}
if(length(which(out))==0){
return(NA)
}else{
return(which(out))
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment