0

I'm trying to pull the letter frequencies from a text file. I want it to create two columns.

The text file for example might have "aabbbbccc".

I want the output to be...

Key    Count
a      2
b      4
c      3

Here's what I have now. I'm sure it's wrong...

mydata3 <- read.table("/Users/ChristopherFlach/Documents/ds710fall2016assignment6/encryptedA.txt", header = FALSE)
as.data.frame(table(strsplit(mydata3,"")))                    
attach(mydata3)
  • 4
    `table(strsplit("aabbbbccc", ''))` – Sotos Oct 13 '16 at 14:20
  • 1
    as.data.frame(table(strsplit("aabbbbccc", ''))) is closer – DarrenRhodes Oct 13 '16 at 14:23
  • If you're using read.table you will be getting a table of data rather than a vector of data. Have a look at the following, http://stackoverflow.com/questions/9068397/import-text-file-as-single-character-string which may work for you. – DarrenRhodes Oct 13 '16 at 14:39
  • There are probably more letters than you think, consider non-English languages and letter frequencies will be different for different languages. – zaph Oct 13 '16 at 16:45

0 Answers0