Edit 2: Updated with starting data
Edit 1: I would like to know how to modify the data or parameters in melt function (might have overlooked or not understood) before melting it to the long form.
I started with the following data:
type1 type2 type3 type4
A 43 0 1 0
B 6 0 1 0
C 16 0 3 1
D 17 0 2 2
When it gets melted, it looks like:
Sample variable count proportion
1 A type1 43 0.97727273
2 A type2 0 0.00000000
3 A type3 1 0.02272727
4 A type4 0 0.00000000
5 B type1 6 0.85714286
6 B type2 0 0.00000000
7 B type3 1 0.14285714
8 B type4 0 0.00000000
9 C type1 16 0.80000000
10 C type2 0 0.00000000
11 C type3 3 0.15000000
12 C type4 1 0.05000000
However, in total there should have type1 to type5 as all possible variables. Since, the data didn't contain any of type 5, it wasn't part of the melted data. I would like to all variables per sample in the table. So for type 5, which the data doesn't have, I would want to have Sample type5 0 0, instead of no entries for it. I have looked at the API of melt and cast but wasn't able to find an answer to the above inquiry.
Any idea? Thanks!