I'm trying to figure out the syntax of working with dplyr and I'm running into problems on how to pass on more than a single column to another function (e.g. str_detect). I want to search through a tibble and select all rows there a certain string is detected. I can run this for a specific column (e.g. col3 in the example below), but would like to look through some and/or all columns.
library(dplyr)
library(stringr)
col1 <- c("plate_ABC", "text", "text", "text")
col2 <- c("text", "this is plate B", "text", "text")
col3 <- c("text", "text", "C-plate", "text")
df <- as_tibble(data_frame(col1, col2, col3))
df %>% filter(str_detect(col3, "plate"))
Output:
df %>% filter(str_detect(col3, "plate"))
## A tibble: 1 x 3
# col1 col2 col3
# <chr> <chr> <chr>
#1 text text C-plate
Desired Output:
df %>% filter(str_detect(?SOME/ALL Cols?, "plate"))
## A tibble: 3 x 3
# col1 col2 col3
# <chr> <chr> <chr>
#1 plate_ABC text text
#2 text this is plate B text
#3 text text C-plate
filter
orreduce
? I am confused – akrunrowwise
should be slow compared to the vectorized option – akrun