简体   繁体   English

如何根据行名删除r中的一行

[英]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"?例如,如果行名称是“Bacteria”,如何仅删除名为“Bacteria”的行?

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.我们可以通过使用带有row.names的比较运算符来创建逻辑向量,并使用该行索引来对行进行子集化。 If df1 is the data.frame object name, then do如果df1是 data.frame 对象名称,则执行

df1[row.names(df1) != "Bacteria", , drop = FALSE]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM