suppose I have a data frame consist of 60 columns and 170 observations. The rating for each of the 60 variables is from 1-7. Now I want to calculate how many "5" are there in the data frame, how should I do that using R?
            Asked
            
        
        
            Active
            
        
            Viewed 40 times
        
    -2
            
            
        - 
                    Try `sum(df == 5)`, but consider to give a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – markus Oct 17 '18 at 13:19
- 
                    Or try `table(as.vector(as.matrix(df)))` – G5W Oct 17 '18 at 13:35
- 
                    thanks, that second answer works – jeff.lian Oct 17 '18 at 13:38
1 Answers
0
            > df <- sample(1:7, 10200, replace=TRUE) %>% 
+     matrix(nc = 60, nr = 170)
> 
> df %>% .[df == 5] %>% plyr::count()
  x freq
1 5 137
 
    
    
        Rγσ ξηg Lιαη Ημ 雷欧
        
- 486
- 2
- 9
- 22
