2016-05-12 33 views
0

我有兩個矩陣df_matrixdf_subset。一個是另一個的子集。因此,df_matrix具有10000行和列,df_subset僅包含8222列和df_matrix行。基於列名稱提取不存在於另一個矩陣中的列

我想從df_matrix不在df_subset只選擇那些。我認爲這是最好的列名,所以我試圖執行此代碼:

newdf <- df_matrix[, which((colnames(df_matrix)) != (colnames(KroneckerProducts)))] 

但是,這根本不起作用。有沒有其他方法可以做到這一點?

+2

在使用'%'%:'df_matrix [!,(colnames(df_matrix)%的%colnames(KroneckerProducts))]' – nicola

+0

@nicola:剛纔說了同樣的話:d – vasanthcullen

回答

4

一般規律是不使用==或!=與

使用%的%與不同長度的對象!

newdf <- df_matrix[, !(colnames(df_matrix) %in% colnames(KroneckerProducts))]