This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Count profiles in R

Hi everybody, I would like to count the occurrences in a dataframe, for example if my dataframe is:

0 0 0 
0 1 0 
0 0 0
1 1 1 
0 1 0

I would like to have the count of each unique combinations.

000 : 3
010 : 2
111 : 1

Anybody have ideas on how I can do it on R ? Thank you.

r

2 answers

I found the function count() of the library plyr. It does exactly what I want. Thank you!

table(df$col1,df$col2) does exactly the same as df %>% count(col1, col2). No reason to use bloated tidyverse when base R can do it :)

EDIT: actually there's a difference: count will not include cases with 0 occurrences. It may or may not be desirable.

Use table().

Log in to answer this question.