This should do the trick:
numchars<-function(txt){
tmpres<-gregexpr('[a-z]', as.character(txt))[[1]]
ifelse(tmpres[1]==-1, 0, length(tmpres))
}
dataset$count <-sapply(dataset$text, numchars)
Another option is a two-step approach:
charmatches<-gregexpr('[a-z]', as.character(dataset$text))[[1]]
dataset$count<-sapply(charmatches, length)
source
share