Can you please give me a hint on what's the best and easiest way to compute the absolute and relative frequencies of vowels in a string using R?
I guess the source code is a bit different from what I've found so far in the forum concerning Java.
Set up some data:
text <- "Can you please give me a hint on what's the best and easiest way to compute the absolute and relative frequencies of vowels in a string using R?
I guess the source code is a bit different from what I've found so far in the forum concerning Java.
Any help is appreciated."
Analyse it:
x <- tolower(strsplit(text, "")[[1]])
x <- x[x %in% letters]
Absolute frequency:
table(x)
x
a b c d e f g h i j l m n o p q r s t u v w y
19 3 8 6 29 8 5 8 17 1 5 4 16 14 5 1 11 16 17 9 5 4 3
Relative frequency:
table(x)/length(x)
x
a b c d e f g h i
0.088785047 0.014018692 0.037383178 0.028037383 0.135514019 0.037383178 0.023364486 0.037383178 0.079439252
j l m n o p q r s
0.004672897 0.023364486 0.018691589 0.074766355 0.065420561 0.023364486 0.004672897 0.051401869 0.074766355
t u v w y
0.079439252 0.042056075 0.023364486 0.018691589 0.014018692
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With