Skip to content
Prev 275240 / 398503 Next

how to delete rows by a list of rownames

I think that only works because the rows are ordered and have no
names: try something more like this:

df1 <- data.frame(1:20, 21:40, 31:50)
rownames(df1) <- sample(letters, 20)

toDrop <- sample(rownames(df1), 5)

df1[ !(rownames(df1) %in% toDrop), ]

or alternatively

toKeep <- sample(rownames(df1), 5)

df1[rownames(df1) %in% toKeep, ]

Michael
On Sun, Oct 23, 2011 at 9:30 AM, B77S <bps0002 at auburn.edu> wrote: