0

I want to use str_count from the stringi package to count special symbols in a string.

Something like this:

library(stringi)
data$var1 <- stri_count(data$var, pattern="[[:punct:]]")

I'm getting the following error.

Error in stri_count(data$var, pattern = "[[:punct:]]") : 
  you have to specify either `regex`, `fixed`, `coll`, or `charclass`

Any ideas?

Prometheus
  • 1,671
  • 1
  • 25
  • 47
  • 2
    You should use `stri_count(data$var, regex="[[:punct:]]")` or `stri_count_regex(data$var, pattern="[[:punct:]]")` – mt1022 May 25 '17 at 13:43
  • @mt1022 thanks. the stringi documentation was a bit vague in respect of inputs. – Prometheus May 25 '17 at 13:44
  • There is even an example of usage [here](https://www.rdocumentation.org/packages/stringi/versions/1.1.5/topics/stri_count). And I even found an SO post related to its usage. Closed as a dupe. – Wiktor Stribiżew May 25 '17 at 13:44

0 Answers0