. :
dia.count <- function(string) {
y <- unlist(strsplit(string, ''))
length(grep('[A-Za-z0-9]', y, value=T))
}
dia.count(x)
[1] 4
. , . .
Update
, :
nchar(sub('[^A-Za-z]+', '', x))
[1] 4
dia.count . script ; , , . @akrun
, stringi, str_enc_toascii, :
stri_enc_toascii(x)
[1] "n\032ala"
, , , , .
nchar(sub('[^A-Za-z]', '', stri_enc_toascii(x)))
[1] 4
A good balance between the general answer and the fast script is in the comments:
nchar(iconv("n̥ala", to="ASCII", sub=""))
[1] 4
This uses a function base R iconvthat converts the string for you. credit @Molx
source
share