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

I know how to count repeated fields in a column simply by using table(file$column)

> exon    intron    CDS    mRNA
   234    235      7564    27465

now I want to know how I can count these fields in a column based on the values of another column, e.g.

col1      col2     col3    col4   col5  col6  col7   col8   col9
scf001    74212    85524    mRNA    -    ERV    1659   1689   30
scf002    35002    48200    CDS     +    ERV2    16     81    62
scf0101    82177    82314   exon    -    DUF    465    615    137
scf00273   74212    85524   intron  +    AZUR    612   766    135

I want to count the number of occurrence for col4 for values of equal or greater than 80 in col9, how can I do that?

r occurrence table
> table(df$col4[df$col9>=80])

  exon intron 
     1      1 

> table(df$col4[df$col9>=80]) |>
+   as.data.frame()

    Var1 Freq
1   exon    1
2 intron    1

1 answer

In the tidyverse:

data %>% filter(col9 >= 80) %>% select(col4) %>% table

Thanks, can you explain what %>% does in this package?

Log in to answer this question.