mrad
mrad

Reputation: 303

How to remove a row in r based on the row name

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

Answers (1)

akrun
akrun

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

Related Questions