I have a character string and need to find the word in the string that occurs most frequently. I've tried every variation of max
, which.max
, sort
, order
, and rank
that I can think of - but can't seem to get the syntax worked out correctly. I've also tried all of the methods found here: Calculate frequency of occurrence in an array using R
Example code:
zzz <- c("jan", "feb", "jan", "mar", "mar", "jan", "feb") #random example data
zzz <- paste(zzz, collapse=" ") #make data look like what I'm working with
zzz
# [1] "jan feb jan mar mar jan feb"
I this example, "jan" occurs most frequently.
Any suggestions are greatly appreciated!