2015-07-13 51 views
0

行,我会建立在这个问题Remove Rows From Data Frame where a Row match a String删除行如果某些变量同上

例如类似:

A,B,org.id 
4,3,Foo 
2,3,Bar 
2,4,Bar 
7,5,Zap 
7,4,Zap 
7,3,Zap 

我怎么会返回排除所有行的数据帧,其中组织.id与上面的行相同?猜测:也许熔化()或cast()函数可以做到这一点。 (我只知道如何在Excel中,在这里我要创建一个新的数据帧,并做这样做,如果[A2 = A1,0,A2〕

问题也类似于Subtract the previous row of data where the id is the same as the row above但在SQL。

回答

1

您可以duplicated

df1[!duplicated(df1$org.id),] 
# A B org.id 
#1 4 3 Foo 
#2 2 3 Bar 
#4 7 5 Zap 

或者使用unique尝试by选项

library(data.table) 
unique(setDT(df1), by='org.id') 
+0

我想**头((dff_all2 [复制(dff_all2 $ ID),C(1,4, 617)]))** #但输出: country_id id device_model频道 177 BR 776962 iPhone5,1(iPhone 5)有机 189 BR 687574 GT-I9505三星SEM 310 BR 1037119 XT1058摩托罗拉有机 439 BR 735454 GT-I8190L三星有机 805 BR 779030 GT-S5360B三星直接 852 BR 661698 iPhone3,1(iPhone 4 GSM)直达 – jacob

+0

@jacob我的代码是基于你展示的例子。请用一个新的例子来更新你的文章(最好用'dput')来引起异常。 – akrun