-4

Could you please get me the proportion by id and by loan purpose for below sample data

Data:

Id  Loan
94  Expansion
94  Working Capital
94  Expansion
95  Working Capital
95  Working Capital
95  Inventory
99  Working Capital
99  Working Capital
99  Working Capital

Desired Output:

Id  Loan              Proportion
94  Expansion       66.67%
94  Working Capital     33.33%
95  Working Capital     83.33%
95  Inventory       16.67%

Thanks, S

d.b
  • 29,772
  • 5
  • 24
  • 63
Sobana
  • 13
  • 3
  • I would like to get proportion by each loan type and ID(column A and Column B)..It means each id will have 100% split up.Your code considering all loans and all ID. – Sobana Mar 07 '17 at 06:03
  • Possible duplicate of [How to use dplyr to generate a frequency table](http://stackoverflow.com/questions/34860535/how-to-use-dplyr-to-generate-a-frequency-table) – Ronak Shah Mar 07 '17 at 06:13
  • 1
    @Sobana Please put the additional information in your question (not in the comment), i.e. edit your question http://stackoverflow.com/posts/42641051/edit Is your desired output correct for `ID==95` ? (You accepted an answer that didn't gave the desired output). – jogo Mar 07 '17 at 07:33
  • 1
    @RonakShah In http://stackoverflow.com/questions/34860535/how-to-use-dplyr-to-generate-a-frequency-table the solution is restricted to `dplyr` – jogo Mar 07 '17 at 07:34

1 Answers1

0

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
thelatemail
  • 81,120
  • 12
  • 111
  • 172