2015-07-13 57 views
0

如何R.ř如何刪除所選行中的數據幀

刪除選定的行我有數據幀(股票)喜歡在下面提供

100, A, B 
101, B, C 
102, A, B 
103, B, C 
104, A, B 
105, B, C 

我有向量(VEC)列表等下面給出。

101 
104 
106 

想要刪除數據框中存在於向量列表中的所有行。

我試圖實現與子集功能相同,但我得到的錯誤/警告

subset(stock,stock$col1 == vec) 

Warning messages: 
1: In is.na(e1) | is.na(e2) : 
longer object length is not a multiple of shorter object length 
2: In `==.default`(stock$col1, vec) : 
longer object length is not a multiple of shorter object length 

如何刪除在數據幀中存在的載體列表中的所有行。請指教。

+0

的[刪除數據幀其細胞匹配給定矢量的行數]可能重複(http://stackoverflow.com/questions/11004203/remove-the-rows-of-data-frame-whose- cell-match-a-given-vector) – 2015-07-13 05:18:39

回答

2

使用此代碼:

stock <- stock[-vec, ] 

是的,這是一個重複,你或許應該花更多的時間去尋找堆棧溢出的數據庫。

+0

對不起,如果是重複的。但我厭倦了在棧上搜索,發現我應該使用子集,因此我對子集函數感到厭倦。由於有錯誤,我做了這篇文章的子集。謝謝無論如何,我幫助拯救了我的一天。 – shakthydoss

2
stock<-stock[!stock$col1 %in% vec[,1],]