简体   繁体   English

如何从 R 中的 dataframe 行中删除特定字符

[英]how to remove specific character from rows of dataframe in R

I have a data frame containing three columns and first column is Species_Name which contain all species name but i want to remove those rows which are undetermined like "Salmonella sp" and want to keep only those rows which have full determined name like Salmonella enterica or bongori and so on.我有一个包含三列的数据框,第一列是 Species_Name,其中包含所有物种名称,但我想删除那些未确定的行,如“Salmonella sp”,并且只想保留那些具有完整名称的行,如沙门氏菌或邦戈里等等。 I tried following code but its not working.我尝试了以下代码,但它不起作用。 please give any suggestions.请提出任何建议。

dfcox1 <- dfcox1 %>%
filter(Species_Name != "Salmonella sp")

Welcome on stackoverflow.com!欢迎访问 stackoverflow.com! Please create reproducible examples so that other people have it easier to help you, which is especially easy when working with GNU R .请创建可重现的示例,以便其他人更容易帮助您, 这在使用 GNU R 时尤其容易

If you want to remove a row in a dataframe according to a specific regular expression (eg the row name ending with sp ), you can do so as follows):如果您想根据特定的正则表达式(例如以sp结尾的行名)删除 dataframe 中的一行,您可以这样做):

iris %>%
  dplyr::filter(!stringr::str_detect(Species, "sp"))

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

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