I need to add about 100
extra columns to data.frame
based on the length of a previous data.frame
For example, I have two data.frame
s Xtrain
and Xtest
. Xtrain
as 1000 columns, but Xtest
has only 900 columns. This difference is due to 1-hot encoding the Xtrain
and Xtest
separately.
How can I add those 100 missing columns (with all 0s) to Xtest
? Also, the order of columns in the augmented Xtest
should be same as Xtrain
.
This is what I have tried so far:
extra = setdiff(names(Xtrain), names(Xtest))
for (e in extra){
Xtest$e <- 0
}
But this adds a column e
not the corresponding entry in extra
.