Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR R

count certain number of alphabets in a string r

# Load your example data
q.data<-data.frame(number=1:3, string=c("greatgreat", "magic", "not"), stringsAsFactors = F)
library(stringr)

# Count the number of 'a's in each element of string
q.data$number.of.a <- str_count(q.data$string, "a")
q.data
#  number     string number.of.a
#1      1 greatgreat           2
#2      2      magic           1
#3      3        not           0
 
PREVIOUS NEXT
Tagged: #count #number #alphabets #string
ADD COMMENT
Topic
Name
6+4 =