Given the following data frame:
z1 z2
1 A X
2 A Y
3 B X
4 B Y
5 C X
6 C Z
7 D X
8 D Z
9 E X
10 E Y
11 F X
12 G Z
13 H X
14 I Y
15 J X
16 K Z
I am trying to find a more efficient (than I came) way of eliminating duplicate values in the first column, z1, given the value in the second column z2, is not the specified value "X". This is the result that I get after:
z1 z2
1 A X
3 B X
5 C X
7 D X
9 E X
11 F X
12 G Z
13 H X
14 I Y
15 J X
16 K Z
( ) , duplicated() unique(), , , , . , , , z1, z2, z2 , z1 , , subset(), , z1, , . , , .
, :
z1=c(rep(c("A","B","C","D","E"),each=2),"F","G","H","I","J","K")
z2=c(rep(c("X","Y"),2),rep(c("X","Z"),2),rep(c("X","Y","X","Z"),2))
z=data.frame(cbind(z1,z2))
t1=subset(z,
(z$z1!="A" | z$z2=="X")&
(z$z1!="B" | z$z2=="X")&
(z$z1!="C" | z$z2=="X")&
(z$z1!="D" | z$z2=="X")&
(z$z1!="E" | z$z2=="X"))
t1
?