Reputation: 129
I have a table of counts in R:
Deg_Maj.tbl <- table(dat1$Maj,dat1$DegCat)
Deg_Maj.tbl
B D
A 66 5
C 2 9
and a table of percentages:
Deg_Maj.ptbl <- round(prop.table(Deg_Maj.tbl)*100,3)
Deg_Maj.ptbl
B D
A 80.48 6.10
C 2.44 10.98
I need to build a table that looks like this:
B D
A 66(80.48%) 5(6.1%)
C 2(2.44%) 9(10.98%)
I have several tables to do in this manner, so I am hoping to find a nice easy way to accomplish this.
Upvotes: 2
Views: 45
Reputation: 886938
We can use paste
Deg_Maj_out <- Deg_Maj.tbl
Deg_Maj_out[] <- paste0(Deg_Maj.tbl, "(", Deg_Maj.ptbl, "%)")
Deg_Maj_out
# B D
#A 66(80.48%) 5(6.1%)
#C 2(2.44%) 9(10.98%)
Upvotes: 2