I am using below code to count occurrence of a word in a given sentence
wordCount = function(sentence,word){
splitedVectorString <- c()
splitedVectorString <- strsplit(sentence," ")
count <- 0
for (j in splitedVectorString) {
print(length(splitedVectorString))
print(splitedVectorString)
print(word)
if (identical(word,j)) {
count <- count + 1
print(count)
}
}
}
Program runs successfully but I'm getting count as 0. I call this function on console as
wordCount("This is XYZ and is running late","is")
When I print length of splited vector splitedVectorString
it gives me 1. Am I getting issue in spliting the sentence ?
Exactly I dont know whats going wrong. I just started learning R programming