user1692342
user1692342

Reputation: 5237

Finding Frequency of each letter in a data frame

I have a data frame which looks the following:

col1 col2 col3
A     B    A
C     A    D
E     A    B

I need to find total number of occurrences of the letters A,B,C,D and E.

I have used lapply along with table function in the following manner:

z =apply(T[,1:3],2,table)

It gives a list of frequency of each letter in each column. Where am I going wrong?

Upvotes: 3

Views: 182

Answers (1)

Dominic Comtois
Dominic Comtois

Reputation: 10431

table(as.matrix(dat))

or as RStudent suggested:

table(unlist(dat))

data

dat<- read.table(text="col1;col2;col3
A;B;A
C;A;D
E;A;B
", header=TRUE, sep=";")

Upvotes: 6

Related Questions