Letter frequency: Difference between revisions
m
→{{header|R}}: Syntax highlighting.
No edit summary |
ReeceGoding (talk | contribs) m (→{{header|R}}: Syntax highlighting.) |
||
Line 5,512:
=={{header|R}}==
===Using summary===
<lang
{
file <- paste(readLines(filename), collapse = '')
Line 5,521:
Usage on itself:
<lang
> letter.frequency('letter.frequency.r')
- , . ' ( ) [ ] { } < = 1 a c d e f h i l L m n N o p q r s t u U y
Line 5,527:
===Using table===
R's table function is more idiomatic. For variety, we will use read.delim rather than readLines and show how to only count letters. It is worth noting that readLines is prone to counting empty lines. This may be undesirable.
<lang
{
txt<-read.delim(filename,header = FALSE,stringsAsFactors = FALSE,allowEscapes = FALSE,quote = "")
|