You can combine tidyr spread and gather with dplyr to get the following single pipeline:
x <- data.frame(A=LETTERS[1:5], as.data.frame(matrix(sample(0:5, 25, T), ncol=5))) y <- x %>% gather(V, val, -A) %>% group_by(A) %>% mutate(perc = val / sum(val)) %>% select(-val) %>% spread(V, perc)
With tidy data strong> it's pretty easy to get any group sum (rows, columns, or any nested -level index) and calculate percentages. spread and gather take you to and from your input format.
TemplateRex
source share