R

Table of Contents

R

Code snippets

Grouping and counting objects

  • Using table
    df <- data.frame(name = c("a", "a", "a", "b", "b", "c", "c", "c", "c"), x = 1:9)
    tt <- table(df$name)
    tt
    
    a b c 
    3 2 4 
    
  • Using dplyr
    library(dplyr)
    df <- data.frame(name = c("a", "a", "a", "b", "b", "c", "c", "c", "c"), x = 1:9)     
    tt <- df %>% group_by(name) %>% summarize( count = n() )
    tt
    
    # A tibble: 3 × 2
        name count
      <fctr> <int>
    1      a     3
    2      b     2
    3      c     4
    

Date: 2017-02-16 gio 00:00

Author: Stefano Rodighiero

Created: 2017-02-18 sab 13:42

Validate