0

I have a dataframe (29 columns), I know that in some columns, there are some lines that contain the string "...".
I would like to create a dataframe that contains only the lines where there is in a column (or more) the string "..".
I can do it with filter or with select but I do not want to list all my columns by hand.
E.g. :

test <- filter(population, pays.Code == ".." | pays.Name == "..")  

Is there a simple way (preferably without making a loop to stay efficient) to do this?

Thanks a lot for your answer.

Axeman
  • 32,068
  • 8
  • 81
  • 94
  • Can you post your data? It is easier for people to try to help when the data is available. You can create code to recreate the data using `dput` – Kerry Jackson Oct 02 '18 at 17:33
  • Are you looking for `".."` or `"..."`? Can you post some data? You might want `filter_all`, `filter_at` or `filter_if`. – Axeman Oct 02 '18 at 17:34
  • 3
    Possible duplicate of [dplyr filter with condition on multiple columns](https://stackoverflow.com/questions/43938863/dplyr-filter-with-condition-on-multiple-columns) – Mako212 Oct 02 '18 at 17:42
  • Thank you all for your answers, I test the response of MR_MPI-BGC. If that does not suit, I'll post the datas. If it works I'll let you know. Thanks Axeman too :-) – Olivier GSCHWIND Oct 02 '18 at 20:09

1 Answers1

2

It can be done using dplyr package. Here is what I think is a minimal example, if I understand your question well.

library(dplyr)
df <- data.frame(col1=c("aaa", "bbb", "ccc"), col2=c("ddd", "bbb", "aaa"))
df %>% filter_all(any_vars(. == "aaa"))

It is what is called scoped filter in dplyr. Hope this helped!

MR_MPI-BGC
  • 265
  • 3
  • 11