With my dataset "chile2", I am doing following calculations:
Tab<-with(chile2,table(Q27,Q12_1_TEXT))
Tab<-as.data.frame.matrix(Tab)
I want the output like below (only 4 columns are shown):

I am trying below code to do manipulations to the columns, which is strangely calculating few columns but not all:
for(col in names(T1)){
T1[col]=(T1[col]*100)/colSums(T1)
}
for(t in names(T1)){
T1[t]=paste(round(T1[t],0),"%")
}
The "All" row can be added after this.
Any other better way to do this?
dput(chile2)
structure(list(Q27 = structure(c(2L, 1L, 2L, 2L, 1L, 2L, 2L,
2L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L), .Label = c("Si",
"No"), class = "factor"), Q12_1_TEXT = c("Abertis Autopistas S.a.",
"Accenture", "Adessa Falabella", "Administradora de Fondos de Cesantía",
"AES GENER S.A.", "AFP HABITAT S.A.", "Agrícola Ariztía", "Agrosuper S.A.",
"Aguas de Antofagasta S.A.", "AIG Chile Compañía de Seguros Generales S.A.",
"Arcos Dorados Restaurantes de Chile Ltda", "Artel", "Arval - Relsa",
"Banchile Inversiones", "BANCO INTERNACIONAL", "BASF CHILE SA",
"BBVA Chile", "BOEHRINGER INGELHEIM LTDA", "Bredenmaster S.A.",
"Caja de Compensación 18 de Septiembre")), class = c("data.table",
"data.frame"), row.names = c(NA, -20L), .internal.selfref = <pointer: 0x0000000000100788>, .Names = c("Q27",
"Q12_1_TEXT"))
addmargins(100*prop.table(Tab, 2), 1)