sophie.h sophie.h - 1 year ago 107
R Question

plot function type

For digits I have done so:

digits <- c("0","1","2","3","4","5","6","7","8","9")

Answer Source

You can use the [:punct:] to detect punctuation. This detects


Either in grepexpr

x = c("we are friends!, Good Friends!!")
gregexpr("[[:punct:]]", x)
R> gregexpr("[[:punct:]]", x)
[1] 15 16 30 31
[1] 1 1 1 1
[1] TRUE

or via stringi

# Gives 4
stringi::stri_count_regex(x, "[:punct:]")

Notice the , is counted as punctuation.

The question seems to be about getting individual counts of particular punctuation marks. @Joba provides a neat answer in the comments:

## Create a vector of punctuation marks you are interested in 
punct = strsplit('[]?!"\'#$%&(){}+*/:;,._`|~[<=>@^-]\\', '')[[1]]

The count how often they appear counts = stringi::stri_count_fixed(x, punct)

Decorate the vector

setNames(counts, punct) 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download