Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Count how many times each character appears in the whole dataset

I have a table with twenty columns and thousands of rows.

Just for example purposes, I will say I have this table:

ColumnA   ColumnB
Testing      This
1231         1231

I want to count how many times each single character appears in the whole dataset.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

So in our toy example we would have

character   nºoftimes
T                3
e                1
s                2
i                2
n                1
g                1
h                1
1                4
2                2
3                2

I was thinking of using some kind of string manipulation, but now sure how can I do this.

>Solution :

Does this work:

data.frame(table(strsplit(toupper(paste0(apply(df, 2, paste0, collapse = ''), collapse = '')), split = '')))
   Var1 Freq
1     1    4
2     2    2
3     3    2
4     E    1
5     G    1
6     H    1
7     I    2
8     N    1
9     S    2
10    T    3
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading