Reputation: 303
If I have a dataframe and the rownames are words rather than numbers, how can I delete a specific row based on its name?
For example if a row name is "Bacteria", how can I delete only that row named "Bacteria"?
Upvotes: 5
Views: 6392
Reputation: 887028
We can create a logical vector by making use of the comparison operator with row.names
and use that row index to subset the rows. If df1
is the data.frame object name, then do
df1[row.names(df1) != "Bacteria", , drop = FALSE]
Upvotes: 7