I am currently working with a dataset where loans are displayed with a purpose for the loan and an associated loan grade for each loan.
The dataset is called loancase and one of the columns is the purpose while another column is grade.
Below I have the matrix which is to be filled in a pairwise manner with proportions. Each row should total to 100 percent meaning each entry is the proportion for that specific purpose that received that grade. For instance, the row for [Car, ] may look like 20, 20, 0, 0, 20, 0, 40.
Note that the current data placeholder is NA and I am trying to replace that with a vector listing each desired entry.
matrix(data = NA, nrow = 14, ncol = 7, dimnames = list(levels(loancase$purpose), levels(loancase$grade)))
How do I achieve this goal of filling in each entry with the desired value? I am currently thinking I use tapply() but don't know how to achieve that. Here is the current code that will go in the place of "NA" but it is not correct as of now.
grades.per.purpose = tapply(loancase$grade, levels(loancase$purpose), sum)