I am having problems to convert this pseudocode to R language. The output of mine is not the correct answer. Could anyone help me, please?
PatternCount(Text, Pattern)
count ← 0
for i ← 0 to |Text| − |Pattern|
if Text(i, |Pattern|) = Pattern
count ← count + 1
return count
I paste here what I have until now:
PatternCount <- function(text, pattern){
times <- 0
for (i in c(0:nchar(text) - nchar(pattern))){
if (substr(text, i, i + nchar(pattern)) == pattern)
times <- times + 1}
return(times)}
Thank you in advance!