使用R从向量中提取指定的单词

jan*_*an5 3 r

我有一个文本,例如

text<- "i am happy today :):)"
Run Code Online (Sandbox Code Playgroud)

我想从文本向量中提取:)并报告其频率

Jos*_*ien 5

这是一个很容易概括的想法:

text<- c("i was happy yesterday :):)",
         "i am happy today :)",
         "will i be happy tomorrow?")

(nchar(text) - nchar(gsub(":)", "", text))) / 2
# [1] 2 1 0
Run Code Online (Sandbox Code Playgroud)