I would like to exclude lines containing a string "REVERSE", but my lines do not match exactly with the word, just contain it.
My input data frame:
Value Name 55 REVERSE223 22 GENJJS 33 REVERSE456 44 GENJKI
My expected output:
Value Name 22 GENJJS 44 GENJKI
First of all, create a data frame. Then, use single square subsetting with apply function to remove rows that contains a specific number.
To remove rows of data from a dataframe based on multiple conditional statements. We use square brackets [ ] with the dataframe and put multiple conditional statements along with AND or OR operator inside it. This slices the dataframe and removes all the rows that do not satisfy the given conditions.
This should do the trick:
df[- grep("REVERSE", df$Name),]
Or a safer version would be:
df[!grepl("REVERSE", df$Name),]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With