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. library(dplyr) 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 <- do.call(cbind, counts) TOT <- apply(ag_data, 1, sum) ag_data <- cbind(Count = lvls, ag_data %>% data.frame, TOT) [[alternative HTML version deleted]]