Extracting specified word from a vector using R

r

Solution

Here's one idea, which would be easy to generalize:

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

Problem

I have a text e.g ``` text<- "i am happy today :):)" ``` I want to extract :) from text vector and report its frequency

Original source

Related problems