Reputation: 207
I understand that you can delete a row by using a negative index.
e <- data.frame(x=seq(1,5,1), y=seq(1,5,1))
e
x y
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
e <- e[-3,]
e
x y
1 1 1
2 2 2
4 4 4
5 5 5
But now I want to delete the row that is numbered 4.
e <- e[-4,]
e
x y
1 1 1
2 2 2
4 4 4
It instead deleted the row that was numbered 5 (but, I guess, indexed at 4).
How can I delete the row "named" #5 even if it is in a different numbered index?
Upvotes: 2
Views: 7756
Reputation: 118779
Try
e[rownames(e) != "4", ]
(or) for multiple entries
e[!rownames(e) %in% c("3", "4"), ]
Upvotes: 7