Currently I have enrolled in a R course and one of the practice exercises is building a R program to count words in a string. We cannot use the function table
but must return an output of the most popular word in a string using conventional means.
i.e. The fox jumped over the cone and the...
So the program would have to return "the" as it is the most popular phrase.
So far I have the following:
string_read<- function(phrase) {
phrase <- strsplit(phrase, " ")[[1]]
for (i in 1:length(phrase)){
phrase.freq <- ....
#if Word already exists then increase counter by 1
}
I've hit a road block however as I'm not sure how to increase the counter for specific words. Can anyone give me a pointer in the right direction? My psuedo code would be something like: "For every word that is looped through, increase wordIndex by 1. If word has already occured before, increase wordIndex counter."