I assume you only want to count, or do you also want to remove :)from the row?
For the account you can do:
length(gregexpr(":)",text)[[1]])
which gives 2. A more generalized solution for a row vector:
sapply(gregexpr(":)",text),length)
Edit:
Josh O'Brien noted that this also returns 1 out of nonexistent :), since gregexprreturns -1in this case. To fix this, you can use:
sapply(gregexpr(":)",text),function(x)sum(x>0))
Which becomes a little less beautiful.
source
share