By converting the outer values to a vector ('Sum') and the proportion (prop.table) of frequencies (table) to 'pSum,' we may generate a data.frame.
v1 <- c(m1)
data.frame(Sum = v1, pSum = as.numeric(prop.table(table(v1))[as.character(v1)]))
Output:
Sum pSum
1 2 0.02777778
2 3 0.05555556
3 4 0.08333333
4 5 0.11111111
5 6 0.13888889
6 7 0.16666667
7 3 0.05555556
8 4 0.08333333
9 5 0.11111111
10 6 0.13888889
11 7 0.16666667
12 8 0.13888889
13 4 0.08333333
14 5 0.11111111
15 6 0.13888889
16 7 0.16666667
17 8 0.13888889
18 9 0.11111111
19 5 0.11111111
20 6 0.13888889
21 7 0.16666667
22 8 0.13888889
23 9 0.11111111
24 10 0.08333333
25 6 0.13888889
26 7 0.16666667
27 8 0.13888889
28 9 0.11111111
29 10 0.08333333
30 11 0.05555556
31 7 0.16666667
32 8 0.13888889
33 9 0.11111111
34 10 0.08333333
35 11 0.05555556
36 12 0.02777778
To get the summarized output, as the above output is too big.
stack(prop.table(table(v1)))[2:1]
# ind values
#1 2 0.02777778
#2 3 0.05555556
#3 4 0.08333333
#4 5 0.11111111
#5 6 0.13888889
#6 7 0.16666667
#7 8 0.13888889
#9 10 0.08333333
#10 11 0.05555556
#11 12 0.02777778
in this case;
m1 <- outer(1:6, 1:6, FUN = `+`)
an alternative is use expand.grid
stack(prop.table(table(do.call(`+`, expand.grid(rep(list(1:6), 2))))))
Elevate Your Expertise with Our Machine Learning Certification Program!