Reputation: 5855
I have a dataframe like z:
z <- matrix(c(1,0,0,1,1,0,0,
1,0,0,0,1,0,0,
0,0,0,0,0,0,0,
0,0,1,0,0,0,0),
nrow=7,
dimnames=list(LETTERS[1:7],NULL))
[,1] [,2] [,3] [,4]
A 1 1 0 0
B 0 0 0 0
C 0 0 0 1
D 1 0 0 0
E 1 1 0 0
F 0 0 0 0
G 0 0 0 0
Now I want to remove the duplicated rows where the values of column 1, 2, and 3 are the same.
The result should be like this:
[,1] [,2] [,3] [,4]
A 1 1 0 0
B 0 0 0 0
D 1 0 0 0
Could anyone help me with this? Many thanks!
Upvotes: 6
Views: 642
Reputation: 4932
> z[rownames(unique(z[,-4])),]
[,1] [,2] [,3] [,4]
A 1 1 0 0
B 0 0 0 0
D 1 0 0 0
Upvotes: 7