我有兩個稀疏矩陣,對於訓練和測試集,我需要刪除每個不在其他列中的列 - 使列中的列都相同。目前,我正與一個循環這樣做,但我敢肯定有一個更有效的方式來做到這一點:如何均衡兩個稀疏矩陣的列
# take out features in training set that are not in test
i<-0
for(feature in [email protected][2][[1]]){
i<-i+1
if(!(feature %in% [email protected][2][[1]])){
removerows<-c(removerows, i)
}
}
testmatrix<-testmatrix[,-removerows]
# and vice versa...
這將是更容易幫助,如果我們有'testmatrix'和'trainmatrix' ... – alexwhan