[r] Remove Rows From Data Frame where a Row matches a String

I do I remove all rows in a dataframe where a certain row meets a string match criteria?

For example:

A,B,C
4,3,Foo
2,3,Bar
7,5,Zap

How would I return a dataframe that excludes all rows where C = Foo:

A,B,C
2,3,Bar
7,5,Zap

This question is related to r dataframe

The answer is


I had a column(A) in a data frame with 3 values in it (yes, no, unknown). I wanted to filter only those rows which had a value "yes" for which this is the code, hope this will help you guys as well --

df <- df [(!(df$A=="no") & !(df$A=="unknown")),]

You can use the dplyr package to easily remove those particular rows.

library(dplyr)
df <- filter(df, C != "Foo")

if you wish to using dplyr, for to remove row "Foo":

df %>%
 filter(!C=="Foo")