[Solved] Finding proportion by Id and by loan purpose in R


Make use of the standard old table and prop.table functions:

tmp <- table(dat)
data.frame(prop.table(tmp ,1))[tmp != 0,]
#  Id            Loan      Freq
#1 94       Expansion 0.6666667
#5 95       Inventory 0.3333333
#7 94 Working Capital 0.3333333
#8 95 Working Capital 0.6666667
#9 99 Working Capital 1.0000000

solved Finding proportion by Id and by loan purpose in R