0

a- b- c- d
1- Aman- cake- red
2-Manish-cookie-blue
3-Anish-cola-black
a-b-c-d
4-Pankaj-kite-green
5-Anuj-jet-brown
a-b-c-d
6-Ami-goat-white

This all data is in single data.frame. I want to find the location of the values (a b c d) other than the header, and ten i want to delete those values from the data.frame.

PANKAJ
  • 39
  • 7
  • 1
    Does this answer your question? [Filter rows which contain a certain string](https://stackoverflow.com/questions/22850026/filter-rows-which-contain-a-certain-string) – MatthewR Feb 09 '20 at 14:48
  • yes it did the work.thank you. – PANKAJ Feb 09 '20 at 15:10

2 Answers2

0
library(dplyr)

df %>% filter(!str_detect(column_name, "a-b-c-d"))
Jakub.Novotny
  • 2,912
  • 2
  • 6
  • 21
0

Maybe there are easier ways of doing what the question asks for, but the following works.

library(dplyr)

pattern <- paste(names(df1), collapse = "|")

df1 %>%
  mutate_all(~(stringr::str_detect(., pattern = pattern))) %>%
  mutate(ok = rowSums(.) != ncol(.)) %>%
  select(ok) %>%
  bind_cols(df1, .) %>%
  dplyr::filter(ok) %>%
  select(-ok)
#  a      b      c     d
#1 1   Aman   cake   red
#2 2 Manish cookie  blue
#3 3  Anish   cola black
#4 4 Pankaj   kite green
#5 5   Anuj    jet brown
#6 6    Ami   goat white

Data.

df1 <- read.table(text = "
a- b- c- d
1- Aman- cake- red
2-Manish-cookie-blue
3-Anish-cola-black
a-b-c-d
4-Pankaj-kite-green
5-Anuj-jet-brown
a-b-c-d
6-Ami-goat-white
", header = TRUE, sep = "-")
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66