我的目标是获取“matr”,按 c1 列对其进行排序,并在 c2 = 1 时保持唯一(c1)。例如,从这段代码中......
c1 = c("a",'a','a','b','b','b','b','c','c')
c2 = c(1,1,0,1,1,0,1,0,0)
matr = as.data.frame(cbind(c1,c2))
one = sqldf('select distinct(c1),c2 from matr where c2 = 1')
vs = sqldf('select distinct(c1),c0,c2 from matr group by c1')
sqldf('select matr.*,one.* from matr
left outer join one
where one.c1 = matr.c1')
到达:
c1 c2
a 1
b 1
c 0
出于某种原因,我在左连接中丢失了 c 行。我只能到达(通过其他连接)
c1 c2
a 1
b 1