rstudio - Applying for loop in R to compute frequency distribution -


suppose have data frame several categorical features. how compute freq distribution table using loop instead of finding individual distributions

i used following code:

data            b  c   1  class 1   1  m  2  class 2   0  f  3  class 3   0  m  4  class 1   1  f     5  class 1   1  f 6  class 2   1  m     7  class 1   0  f    8  class 1   0  f  9  class 2   1  m     10 class 2   1  m  11 class 3   1  f     12 class 3   0  f      >b<-data$b >b.freq<-table(b) >b.freq  0  1 5  7 

i want variables in larger set loop.

please help

thanks

if want apply table function columns, can use lapply:

> lapply(data, table) $a  class 1 class 2 class 3        5       4       3   $b  0 1  5 7   $c  f m  7 5  

update: how create plots:

par(mfrow = c(1, length(data)));  lapply(data, function(x) barplot(table(x))) 

enter image description here


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -