Hi, please help with this, I need to insert missing values into a matrix for a regression analysis.
I have made up an example. The first three columns are variables with levels and the next 3 are values, the 4th column missing values should be replaced by 0s, and 5th and 6th column missing values replaced by NA. The final table should have all combinations of the variables in columns 1 , 2 and 3.
The example has just 2 or 3 levels of each variable, the actual data might have upto 50 levels.
Input
Var1 Var2 Var3 Val1 Val2 Val3
X1 L1 G1 1 4 7
X2 L2 G2 2 5 8
X2 L3 G1 3 6 9
Output
Var1 Var2 Var3 Val1 Val2 Val3
X1 L1 G1 1 4 7
X1 L1 G2 0 NA NA
X1 L2 G1 0 NA NA
X1 L2 G2 0 NA NA
X1 L3 G1 0 NA NA
X1 L3 G2 0 NA NA
X2 L1 G1 0 NA NA
X2 L1 G2 0 NA NA
X2 L2 G1 0 NA NA
X2 L2 G2 2 5 8
X2 L3 G1 3 6 9
X2 L3 G2 0 NA NA