2011-12-15 58 views
3

我想選擇兩列A和B相等的數據框中的行。我試過這個:在兩列相等的數據框中查找行

A <- c(0,1,2) 
B <- c(2,1.000001,0) 
df <- as.data.frame(cbind(A,B)) 
subset(df,A==B) # does not work 
# [1] A B 
# <0 rows> (or 0-length row.names) 
subset(df,round(A,3)==round(B,3)) # does work 
# A  B 
# 2 1 1.000001 
subset(df,A==B) 

這不是作業。謝謝。

+0

-1爲模糊的「沒有工作」 - 錯誤信息? – 2011-12-15 12:49:18

+0

使這個可重複的例子請... +1爲模糊 – 2011-12-15 12:53:21

回答

12
mteq <- mtcars[mtcars$gear==mtcars$carb,] 
相關問題