Letter frequency: Difference between revisions

m
→‎{{header|R}}: Syntax highlighting.
No edit summary
m (→‎{{header|R}}: Syntax highlighting.)
Line 5,512:
=={{header|R}}==
===Using summary===
<lang Rrsplus>letter.frequency <- function(filename)
{
file <- paste(readLines(filename), collapse = '')
Line 5,521:
Usage on itself:
 
<lang Rrsplus>> source('letter.frequency.r')
> 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 Rrsplus>letterFreq<-function(filename,lettersOnly)
{
txt<-read.delim(filename,header = FALSE,stringsAsFactors = FALSE,allowEscapes = FALSE,quote = "")
331

edits