RW: Banner using R (Alexandros Kouretsis)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

RW: Banner using R (Alexandros Kouretsis)

Alexandros Kouretsis
This might be slightly tricky. You can use factor levels and table to take
into account that B is missing from the third column. Just introducing
dplyr library for piping.


Data <- data.frame(v1 = c('A', 'B' ,'B' ,'A', 'B'), v2 = c('A', 'B', 'A',
'A', 'B'), v3 = c('A', 'A', 'A', 'A', 'A'))

lvls <- lapply(Data, unique) %>% unlist %>% unique

c_counts <- lapply(Data, function(x){
  levels(x) <- lvls
  x %>% table

ag_data <-, counts)
TOT <- apply(ag_data, 1, sum)

ag_data <- cbind(Count = lvls, ag_data %>% data.frame, TOT)

        [[alternative HTML version deleted]]

[hidden email] mailing list -- To UNSUBSCRIBE and more, see
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.