Filter_at selected columns with multiple str_detect patternsHow to sort a dataframe by multiple column(s)how to make a bar plot for a list of dataframes?how to make a network of user in a dataframe?error “no applicable method for 'regroup' applied to an object of class ”c('integer', 'numeric')“”“minimum count is not zero” error for zero inflated modelMatplot not plotting datasetAdd secondary X-axis with facetsR error: “invalid type (NULL) for variable”R- How to use map() into map()How can I add a regression plot for a multiple regression for certain x values?

Is there really no use for MD5 anymore?

Do I have an "anti-research" personality?

What does ゆーか mean?

Don’t seats that recline flat defeat the purpose of having seatbelts?

How to limit Drive Letters Windows assigns to new removable USB drives

Aliens crash on Earth and go into stasis to wait for technology to fix their ship

What are the characteristics of a typeless programming language?

Check if a string is entirely made of the same substring

"You've called the wrong number" or "You called the wrong number"

Can we say “you can pay when the order gets ready”?

As an international instructor, should I openly talk about my accent?

Why did C use the -> operator instead of reusing the . operator?

Why do games have consumables?

Does a large simulator bay have standard public address announcements?

Pulling the rope with one hand is as heavy as with two hands?

A strange hotel

What happened to Captain America in Endgame?

How much cash can I safely carry into the USA and avoid civil forfeiture?

Why must Chinese maps be obfuscated?

Is the claim "Employers won't employ people with no 'social media presence'" realistic?

On The Origin of Dissonant Chords

Apply MapThread to all but one variable

Alignment of various blocks in tikz

How to pronounce 'c++' in Spanish



Filter_at selected columns with multiple str_detect patterns


How to sort a dataframe by multiple column(s)how to make a bar plot for a list of dataframes?how to make a network of user in a dataframe?error “no applicable method for 'regroup' applied to an object of class ”c('integer', 'numeric')“”“minimum count is not zero” error for zero inflated modelMatplot not plotting datasetAdd secondary X-axis with facetsR error: “invalid type (NULL) for variable”R- How to use map() into map()How can I add a regression plot for a multiple regression for certain x values?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















What i should do should be pretty easy, yet, the newcomer that I am, I spent way too much time on trying to achieve this. With this script I try to filter out ALL observations from a data frame that contain ANY of the mentioned patterns.



The script is:



df1 <- filter_at(df, vars(contains("Pair")), 
any_vars(str_detect(., pattern="quinoaquinoa|lupinelupine", negate=TRUE)))


I do not get any error when I run this, however nothing changes and the expressions are not taken out from the dataframe. As i understand these functions i could also place a ! in front of str_detect instead of the negate=TRUE, however neither works.



Note, the data frame is actually larger (has columns other than those containing "Pair", and the patterns to filter out will always be different and are retrieved from another data frame.



The data frame looks like:



str(df)

'data.frame': 653 obs. of 6 variables:
$ Pair_1: Factor w/ 7 levels "grasscloverleycamelina",..: 3 7 7 3 3 3 7 6 6 6 ...
$ Pair_2: Factor w/ 20 levels "camelinacamelina",..: 10 6 6 8 8 10 6 8 8 10 ...
$ Pair_3: Factor w/ 20 levels "camelinacamelina",..: 19 20 20 20 19 19 20 20 20 16 ...
$ Pair_4: Factor w/ 23 levels "camelinacamelina",..: 9 8 8 8 9 9 4 1 1 5 ...
$ Pair_5: Factor w/ 20 levels "camelinacamelina",..: 9 12 16 16 13 13 12 12 11 11 ...
$ Pair_6: Factor w/ 20 levels "camelinacamelina",..: 20 13 9 17 20 20 5 7 8 8 ...


dput dataframe:



structure(list(Pair_1 = structure(c(3L, 7L, 7L, 3L, 3L, 3L), .Label = c("grasscloverleycamelina", 
"grasscloverleyquinoa", "lupinecamelina", "lupinegrasscloverley",
"lupinelupine", "lupinequinoa", "lupinespringcereal"), class = "factor"),
Pair_2 = structure(c(10L, 6L, 6L, 8L, 8L, 10L), .Label = c("camelinacamelina",
"camelinagrasscloverley", "camelinalupine", "camelinaquinoa",
"camelinaspringcereal", "grasscloverleycamelina", "grasscloverleygrasscloverley",
"grasscloverleylupine", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"quinoacamelina", "quinoagrasscloverley", "quinoalupine",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcereallupine", "springcerealquinoa",
"springcerealspringcereal"), class = "factor"), Pair_3 = structure(c(19L,
20L, 20L, 20L, 19L, 19L), .Label = c("camelinacamelina",
"camelinagrasscloverley", "camelinalupine", "camelinaquinoa",
"camelinaspringcereal", "grasscloverleycamelina", "grasscloverleygrasscloverley",
"grasscloverleylupine", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"quinoacamelina", "quinoagrasscloverley", "quinoalupine",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcereallupine", "springcerealquinoa",
"springcerealspringcereal"), class = "factor"), Pair_4 = structure(c(9L,
8L, 8L, 8L, 9L, 9L), .Label = c("camelinacamelina", "camelinagrasscloverley",
"camelinalupine", "camelinaquinoa", "camelinaspringcereal",
"grasscloverleycamelina", "grasscloverleygrasscloverley",
"grasscloverleyquinoa", "grasscloverleyspringcereal", "lupinecamelina",
"lupinegrasscloverley", "lupinelupine", "lupinequinoa", "lupinespringcereal",
"quinoacamelina", "quinoagrasscloverley", "quinoaquinoa",
"quinoaspringcereal", "springcerealcamelina", "springcerealgrasscloverley",
"springcereallupine", "springcerealquinoa", "springcerealspringcereal"
), class = "factor"), Pair_5 = structure(c(9L, 12L, 16L,
16L, 13L, 13L), .Label = c("camelinacamelina", "camelinagrasscloverley",
"camelinaquinoa", "camelinaspringcereal", "grasscloverleycamelina",
"grasscloverleygrasscloverley", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"lupinecamelina", "lupinegrasscloverley", "lupinequinoa",
"lupinespringcereal", "quinoacamelina", "quinoagrasscloverley",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcerealquinoa", "springcerealspringcereal"
), class = "factor"), Pair_6 = structure(c(20L, 13L, 9L,
17L, 20L, 20L), .Label = c("camelinacamelina", "camelinagrasscloverley",
"camelinaquinoa", "camelinaspringcereal", "grasscloverleycamelina",
"grasscloverleygrasscloverley", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"lupinecamelina", "lupinegrasscloverley", "lupinequinoa",
"lupinespringcereal", "quinoacamelina", "quinoagrasscloverley",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcerealquinoa", "springcerealspringcereal"
), class = "factor")), row.names = c(NA, 6L), class = "data.frame")









share|improve this question



















  • 1





    Please also format inline code for readability, I helped you this time.

    – jay.sf
    Mar 9 at 9:43

















-1















What i should do should be pretty easy, yet, the newcomer that I am, I spent way too much time on trying to achieve this. With this script I try to filter out ALL observations from a data frame that contain ANY of the mentioned patterns.



The script is:



df1 <- filter_at(df, vars(contains("Pair")), 
any_vars(str_detect(., pattern="quinoaquinoa|lupinelupine", negate=TRUE)))


I do not get any error when I run this, however nothing changes and the expressions are not taken out from the dataframe. As i understand these functions i could also place a ! in front of str_detect instead of the negate=TRUE, however neither works.



Note, the data frame is actually larger (has columns other than those containing "Pair", and the patterns to filter out will always be different and are retrieved from another data frame.



The data frame looks like:



str(df)

'data.frame': 653 obs. of 6 variables:
$ Pair_1: Factor w/ 7 levels "grasscloverleycamelina",..: 3 7 7 3 3 3 7 6 6 6 ...
$ Pair_2: Factor w/ 20 levels "camelinacamelina",..: 10 6 6 8 8 10 6 8 8 10 ...
$ Pair_3: Factor w/ 20 levels "camelinacamelina",..: 19 20 20 20 19 19 20 20 20 16 ...
$ Pair_4: Factor w/ 23 levels "camelinacamelina",..: 9 8 8 8 9 9 4 1 1 5 ...
$ Pair_5: Factor w/ 20 levels "camelinacamelina",..: 9 12 16 16 13 13 12 12 11 11 ...
$ Pair_6: Factor w/ 20 levels "camelinacamelina",..: 20 13 9 17 20 20 5 7 8 8 ...


dput dataframe:



structure(list(Pair_1 = structure(c(3L, 7L, 7L, 3L, 3L, 3L), .Label = c("grasscloverleycamelina", 
"grasscloverleyquinoa", "lupinecamelina", "lupinegrasscloverley",
"lupinelupine", "lupinequinoa", "lupinespringcereal"), class = "factor"),
Pair_2 = structure(c(10L, 6L, 6L, 8L, 8L, 10L), .Label = c("camelinacamelina",
"camelinagrasscloverley", "camelinalupine", "camelinaquinoa",
"camelinaspringcereal", "grasscloverleycamelina", "grasscloverleygrasscloverley",
"grasscloverleylupine", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"quinoacamelina", "quinoagrasscloverley", "quinoalupine",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcereallupine", "springcerealquinoa",
"springcerealspringcereal"), class = "factor"), Pair_3 = structure(c(19L,
20L, 20L, 20L, 19L, 19L), .Label = c("camelinacamelina",
"camelinagrasscloverley", "camelinalupine", "camelinaquinoa",
"camelinaspringcereal", "grasscloverleycamelina", "grasscloverleygrasscloverley",
"grasscloverleylupine", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"quinoacamelina", "quinoagrasscloverley", "quinoalupine",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcereallupine", "springcerealquinoa",
"springcerealspringcereal"), class = "factor"), Pair_4 = structure(c(9L,
8L, 8L, 8L, 9L, 9L), .Label = c("camelinacamelina", "camelinagrasscloverley",
"camelinalupine", "camelinaquinoa", "camelinaspringcereal",
"grasscloverleycamelina", "grasscloverleygrasscloverley",
"grasscloverleyquinoa", "grasscloverleyspringcereal", "lupinecamelina",
"lupinegrasscloverley", "lupinelupine", "lupinequinoa", "lupinespringcereal",
"quinoacamelina", "quinoagrasscloverley", "quinoaquinoa",
"quinoaspringcereal", "springcerealcamelina", "springcerealgrasscloverley",
"springcereallupine", "springcerealquinoa", "springcerealspringcereal"
), class = "factor"), Pair_5 = structure(c(9L, 12L, 16L,
16L, 13L, 13L), .Label = c("camelinacamelina", "camelinagrasscloverley",
"camelinaquinoa", "camelinaspringcereal", "grasscloverleycamelina",
"grasscloverleygrasscloverley", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"lupinecamelina", "lupinegrasscloverley", "lupinequinoa",
"lupinespringcereal", "quinoacamelina", "quinoagrasscloverley",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcerealquinoa", "springcerealspringcereal"
), class = "factor"), Pair_6 = structure(c(20L, 13L, 9L,
17L, 20L, 20L), .Label = c("camelinacamelina", "camelinagrasscloverley",
"camelinaquinoa", "camelinaspringcereal", "grasscloverleycamelina",
"grasscloverleygrasscloverley", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"lupinecamelina", "lupinegrasscloverley", "lupinequinoa",
"lupinespringcereal", "quinoacamelina", "quinoagrasscloverley",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcerealquinoa", "springcerealspringcereal"
), class = "factor")), row.names = c(NA, 6L), class = "data.frame")









share|improve this question



















  • 1





    Please also format inline code for readability, I helped you this time.

    – jay.sf
    Mar 9 at 9:43













-1












-1








-1








What i should do should be pretty easy, yet, the newcomer that I am, I spent way too much time on trying to achieve this. With this script I try to filter out ALL observations from a data frame that contain ANY of the mentioned patterns.



The script is:



df1 <- filter_at(df, vars(contains("Pair")), 
any_vars(str_detect(., pattern="quinoaquinoa|lupinelupine", negate=TRUE)))


I do not get any error when I run this, however nothing changes and the expressions are not taken out from the dataframe. As i understand these functions i could also place a ! in front of str_detect instead of the negate=TRUE, however neither works.



Note, the data frame is actually larger (has columns other than those containing "Pair", and the patterns to filter out will always be different and are retrieved from another data frame.



The data frame looks like:



str(df)

'data.frame': 653 obs. of 6 variables:
$ Pair_1: Factor w/ 7 levels "grasscloverleycamelina",..: 3 7 7 3 3 3 7 6 6 6 ...
$ Pair_2: Factor w/ 20 levels "camelinacamelina",..: 10 6 6 8 8 10 6 8 8 10 ...
$ Pair_3: Factor w/ 20 levels "camelinacamelina",..: 19 20 20 20 19 19 20 20 20 16 ...
$ Pair_4: Factor w/ 23 levels "camelinacamelina",..: 9 8 8 8 9 9 4 1 1 5 ...
$ Pair_5: Factor w/ 20 levels "camelinacamelina",..: 9 12 16 16 13 13 12 12 11 11 ...
$ Pair_6: Factor w/ 20 levels "camelinacamelina",..: 20 13 9 17 20 20 5 7 8 8 ...


dput dataframe:



structure(list(Pair_1 = structure(c(3L, 7L, 7L, 3L, 3L, 3L), .Label = c("grasscloverleycamelina", 
"grasscloverleyquinoa", "lupinecamelina", "lupinegrasscloverley",
"lupinelupine", "lupinequinoa", "lupinespringcereal"), class = "factor"),
Pair_2 = structure(c(10L, 6L, 6L, 8L, 8L, 10L), .Label = c("camelinacamelina",
"camelinagrasscloverley", "camelinalupine", "camelinaquinoa",
"camelinaspringcereal", "grasscloverleycamelina", "grasscloverleygrasscloverley",
"grasscloverleylupine", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"quinoacamelina", "quinoagrasscloverley", "quinoalupine",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcereallupine", "springcerealquinoa",
"springcerealspringcereal"), class = "factor"), Pair_3 = structure(c(19L,
20L, 20L, 20L, 19L, 19L), .Label = c("camelinacamelina",
"camelinagrasscloverley", "camelinalupine", "camelinaquinoa",
"camelinaspringcereal", "grasscloverleycamelina", "grasscloverleygrasscloverley",
"grasscloverleylupine", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"quinoacamelina", "quinoagrasscloverley", "quinoalupine",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcereallupine", "springcerealquinoa",
"springcerealspringcereal"), class = "factor"), Pair_4 = structure(c(9L,
8L, 8L, 8L, 9L, 9L), .Label = c("camelinacamelina", "camelinagrasscloverley",
"camelinalupine", "camelinaquinoa", "camelinaspringcereal",
"grasscloverleycamelina", "grasscloverleygrasscloverley",
"grasscloverleyquinoa", "grasscloverleyspringcereal", "lupinecamelina",
"lupinegrasscloverley", "lupinelupine", "lupinequinoa", "lupinespringcereal",
"quinoacamelina", "quinoagrasscloverley", "quinoaquinoa",
"quinoaspringcereal", "springcerealcamelina", "springcerealgrasscloverley",
"springcereallupine", "springcerealquinoa", "springcerealspringcereal"
), class = "factor"), Pair_5 = structure(c(9L, 12L, 16L,
16L, 13L, 13L), .Label = c("camelinacamelina", "camelinagrasscloverley",
"camelinaquinoa", "camelinaspringcereal", "grasscloverleycamelina",
"grasscloverleygrasscloverley", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"lupinecamelina", "lupinegrasscloverley", "lupinequinoa",
"lupinespringcereal", "quinoacamelina", "quinoagrasscloverley",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcerealquinoa", "springcerealspringcereal"
), class = "factor"), Pair_6 = structure(c(20L, 13L, 9L,
17L, 20L, 20L), .Label = c("camelinacamelina", "camelinagrasscloverley",
"camelinaquinoa", "camelinaspringcereal", "grasscloverleycamelina",
"grasscloverleygrasscloverley", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"lupinecamelina", "lupinegrasscloverley", "lupinequinoa",
"lupinespringcereal", "quinoacamelina", "quinoagrasscloverley",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcerealquinoa", "springcerealspringcereal"
), class = "factor")), row.names = c(NA, 6L), class = "data.frame")









share|improve this question
















What i should do should be pretty easy, yet, the newcomer that I am, I spent way too much time on trying to achieve this. With this script I try to filter out ALL observations from a data frame that contain ANY of the mentioned patterns.



The script is:



df1 <- filter_at(df, vars(contains("Pair")), 
any_vars(str_detect(., pattern="quinoaquinoa|lupinelupine", negate=TRUE)))


I do not get any error when I run this, however nothing changes and the expressions are not taken out from the dataframe. As i understand these functions i could also place a ! in front of str_detect instead of the negate=TRUE, however neither works.



Note, the data frame is actually larger (has columns other than those containing "Pair", and the patterns to filter out will always be different and are retrieved from another data frame.



The data frame looks like:



str(df)

'data.frame': 653 obs. of 6 variables:
$ Pair_1: Factor w/ 7 levels "grasscloverleycamelina",..: 3 7 7 3 3 3 7 6 6 6 ...
$ Pair_2: Factor w/ 20 levels "camelinacamelina",..: 10 6 6 8 8 10 6 8 8 10 ...
$ Pair_3: Factor w/ 20 levels "camelinacamelina",..: 19 20 20 20 19 19 20 20 20 16 ...
$ Pair_4: Factor w/ 23 levels "camelinacamelina",..: 9 8 8 8 9 9 4 1 1 5 ...
$ Pair_5: Factor w/ 20 levels "camelinacamelina",..: 9 12 16 16 13 13 12 12 11 11 ...
$ Pair_6: Factor w/ 20 levels "camelinacamelina",..: 20 13 9 17 20 20 5 7 8 8 ...


dput dataframe:



structure(list(Pair_1 = structure(c(3L, 7L, 7L, 3L, 3L, 3L), .Label = c("grasscloverleycamelina", 
"grasscloverleyquinoa", "lupinecamelina", "lupinegrasscloverley",
"lupinelupine", "lupinequinoa", "lupinespringcereal"), class = "factor"),
Pair_2 = structure(c(10L, 6L, 6L, 8L, 8L, 10L), .Label = c("camelinacamelina",
"camelinagrasscloverley", "camelinalupine", "camelinaquinoa",
"camelinaspringcereal", "grasscloverleycamelina", "grasscloverleygrasscloverley",
"grasscloverleylupine", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"quinoacamelina", "quinoagrasscloverley", "quinoalupine",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcereallupine", "springcerealquinoa",
"springcerealspringcereal"), class = "factor"), Pair_3 = structure(c(19L,
20L, 20L, 20L, 19L, 19L), .Label = c("camelinacamelina",
"camelinagrasscloverley", "camelinalupine", "camelinaquinoa",
"camelinaspringcereal", "grasscloverleycamelina", "grasscloverleygrasscloverley",
"grasscloverleylupine", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"quinoacamelina", "quinoagrasscloverley", "quinoalupine",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcereallupine", "springcerealquinoa",
"springcerealspringcereal"), class = "factor"), Pair_4 = structure(c(9L,
8L, 8L, 8L, 9L, 9L), .Label = c("camelinacamelina", "camelinagrasscloverley",
"camelinalupine", "camelinaquinoa", "camelinaspringcereal",
"grasscloverleycamelina", "grasscloverleygrasscloverley",
"grasscloverleyquinoa", "grasscloverleyspringcereal", "lupinecamelina",
"lupinegrasscloverley", "lupinelupine", "lupinequinoa", "lupinespringcereal",
"quinoacamelina", "quinoagrasscloverley", "quinoaquinoa",
"quinoaspringcereal", "springcerealcamelina", "springcerealgrasscloverley",
"springcereallupine", "springcerealquinoa", "springcerealspringcereal"
), class = "factor"), Pair_5 = structure(c(9L, 12L, 16L,
16L, 13L, 13L), .Label = c("camelinacamelina", "camelinagrasscloverley",
"camelinaquinoa", "camelinaspringcereal", "grasscloverleycamelina",
"grasscloverleygrasscloverley", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"lupinecamelina", "lupinegrasscloverley", "lupinequinoa",
"lupinespringcereal", "quinoacamelina", "quinoagrasscloverley",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcerealquinoa", "springcerealspringcereal"
), class = "factor"), Pair_6 = structure(c(20L, 13L, 9L,
17L, 20L, 20L), .Label = c("camelinacamelina", "camelinagrasscloverley",
"camelinaquinoa", "camelinaspringcereal", "grasscloverleycamelina",
"grasscloverleygrasscloverley", "grasscloverleyquinoa", "grasscloverleyspringcereal",
"lupinecamelina", "lupinegrasscloverley", "lupinequinoa",
"lupinespringcereal", "quinoacamelina", "quinoagrasscloverley",
"quinoaquinoa", "quinoaspringcereal", "springcerealcamelina",
"springcerealgrasscloverley", "springcerealquinoa", "springcerealspringcereal"
), class = "factor")), row.names = c(NA, 6L), class = "data.frame")






r regex filter dplyr






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 13 at 7:42









Wiktor Stribiżew

332k16149232




332k16149232










asked Mar 9 at 9:16









BellaLinBellaLin

33




33







  • 1





    Please also format inline code for readability, I helped you this time.

    – jay.sf
    Mar 9 at 9:43












  • 1





    Please also format inline code for readability, I helped you this time.

    – jay.sf
    Mar 9 at 9:43







1




1





Please also format inline code for readability, I helped you this time.

– jay.sf
Mar 9 at 9:43





Please also format inline code for readability, I helped you this time.

– jay.sf
Mar 9 at 9:43












2 Answers
2






active

oldest

votes


















0














You can loop over column which has "Pair" in the dataframe check if the required pattern in present or not, create a matrix of logical vectors and select rows which have no occurrence of the pattern.



cols <- grep("Pair", names(df))
df[rowSums(sapply(df[cols],function(x) grepl("quinoaquinoa|lupinelupine", x)))== 0, ]





share|improve this answer























  • Thanks, it works! Would you mind explaining a bit how this one works?

    – BellaLin
    Mar 10 at 7:41











  • @BellaLin Using grep we first find out our columns which has "Pair" in it. Then we loop over those columns using sapply and check which of them have the required pattern in it. Just run sapply(df[cols],function(x) grepl("quinoaquinoa|lupinelupine", x)) and you'll get a matrix with TRUE/FALSE value in it indicating whether the pattern is present in it or not. Now we do rowSums and select only those rows which has no occurrence of the pattern at all in their row. (== 0).

    – Ronak Shah
    Mar 10 at 8:25



















0














There is no string containing "quinoaquinoa" or "lupinelupine" in your dataframe. I think the pattern you're using is inccorect. This works : filter_at(df, vars(contains("Pair")), any_vars(str_detect(., pattern = "quinoa|lupine")))






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55075782%2ffilter-at-selected-columns-with-multiple-str-detect-patterns%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can loop over column which has "Pair" in the dataframe check if the required pattern in present or not, create a matrix of logical vectors and select rows which have no occurrence of the pattern.



    cols <- grep("Pair", names(df))
    df[rowSums(sapply(df[cols],function(x) grepl("quinoaquinoa|lupinelupine", x)))== 0, ]





    share|improve this answer























    • Thanks, it works! Would you mind explaining a bit how this one works?

      – BellaLin
      Mar 10 at 7:41











    • @BellaLin Using grep we first find out our columns which has "Pair" in it. Then we loop over those columns using sapply and check which of them have the required pattern in it. Just run sapply(df[cols],function(x) grepl("quinoaquinoa|lupinelupine", x)) and you'll get a matrix with TRUE/FALSE value in it indicating whether the pattern is present in it or not. Now we do rowSums and select only those rows which has no occurrence of the pattern at all in their row. (== 0).

      – Ronak Shah
      Mar 10 at 8:25
















    0














    You can loop over column which has "Pair" in the dataframe check if the required pattern in present or not, create a matrix of logical vectors and select rows which have no occurrence of the pattern.



    cols <- grep("Pair", names(df))
    df[rowSums(sapply(df[cols],function(x) grepl("quinoaquinoa|lupinelupine", x)))== 0, ]





    share|improve this answer























    • Thanks, it works! Would you mind explaining a bit how this one works?

      – BellaLin
      Mar 10 at 7:41











    • @BellaLin Using grep we first find out our columns which has "Pair" in it. Then we loop over those columns using sapply and check which of them have the required pattern in it. Just run sapply(df[cols],function(x) grepl("quinoaquinoa|lupinelupine", x)) and you'll get a matrix with TRUE/FALSE value in it indicating whether the pattern is present in it or not. Now we do rowSums and select only those rows which has no occurrence of the pattern at all in their row. (== 0).

      – Ronak Shah
      Mar 10 at 8:25














    0












    0








    0







    You can loop over column which has "Pair" in the dataframe check if the required pattern in present or not, create a matrix of logical vectors and select rows which have no occurrence of the pattern.



    cols <- grep("Pair", names(df))
    df[rowSums(sapply(df[cols],function(x) grepl("quinoaquinoa|lupinelupine", x)))== 0, ]





    share|improve this answer













    You can loop over column which has "Pair" in the dataframe check if the required pattern in present or not, create a matrix of logical vectors and select rows which have no occurrence of the pattern.



    cols <- grep("Pair", names(df))
    df[rowSums(sapply(df[cols],function(x) grepl("quinoaquinoa|lupinelupine", x)))== 0, ]






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 9 at 9:44









    Ronak ShahRonak Shah

    50k104370




    50k104370












    • Thanks, it works! Would you mind explaining a bit how this one works?

      – BellaLin
      Mar 10 at 7:41











    • @BellaLin Using grep we first find out our columns which has "Pair" in it. Then we loop over those columns using sapply and check which of them have the required pattern in it. Just run sapply(df[cols],function(x) grepl("quinoaquinoa|lupinelupine", x)) and you'll get a matrix with TRUE/FALSE value in it indicating whether the pattern is present in it or not. Now we do rowSums and select only those rows which has no occurrence of the pattern at all in their row. (== 0).

      – Ronak Shah
      Mar 10 at 8:25


















    • Thanks, it works! Would you mind explaining a bit how this one works?

      – BellaLin
      Mar 10 at 7:41











    • @BellaLin Using grep we first find out our columns which has "Pair" in it. Then we loop over those columns using sapply and check which of them have the required pattern in it. Just run sapply(df[cols],function(x) grepl("quinoaquinoa|lupinelupine", x)) and you'll get a matrix with TRUE/FALSE value in it indicating whether the pattern is present in it or not. Now we do rowSums and select only those rows which has no occurrence of the pattern at all in their row. (== 0).

      – Ronak Shah
      Mar 10 at 8:25

















    Thanks, it works! Would you mind explaining a bit how this one works?

    – BellaLin
    Mar 10 at 7:41





    Thanks, it works! Would you mind explaining a bit how this one works?

    – BellaLin
    Mar 10 at 7:41













    @BellaLin Using grep we first find out our columns which has "Pair" in it. Then we loop over those columns using sapply and check which of them have the required pattern in it. Just run sapply(df[cols],function(x) grepl("quinoaquinoa|lupinelupine", x)) and you'll get a matrix with TRUE/FALSE value in it indicating whether the pattern is present in it or not. Now we do rowSums and select only those rows which has no occurrence of the pattern at all in their row. (== 0).

    – Ronak Shah
    Mar 10 at 8:25






    @BellaLin Using grep we first find out our columns which has "Pair" in it. Then we loop over those columns using sapply and check which of them have the required pattern in it. Just run sapply(df[cols],function(x) grepl("quinoaquinoa|lupinelupine", x)) and you'll get a matrix with TRUE/FALSE value in it indicating whether the pattern is present in it or not. Now we do rowSums and select only those rows which has no occurrence of the pattern at all in their row. (== 0).

    – Ronak Shah
    Mar 10 at 8:25














    0














    There is no string containing "quinoaquinoa" or "lupinelupine" in your dataframe. I think the pattern you're using is inccorect. This works : filter_at(df, vars(contains("Pair")), any_vars(str_detect(., pattern = "quinoa|lupine")))






    share|improve this answer



























      0














      There is no string containing "quinoaquinoa" or "lupinelupine" in your dataframe. I think the pattern you're using is inccorect. This works : filter_at(df, vars(contains("Pair")), any_vars(str_detect(., pattern = "quinoa|lupine")))






      share|improve this answer

























        0












        0








        0







        There is no string containing "quinoaquinoa" or "lupinelupine" in your dataframe. I think the pattern you're using is inccorect. This works : filter_at(df, vars(contains("Pair")), any_vars(str_detect(., pattern = "quinoa|lupine")))






        share|improve this answer













        There is no string containing "quinoaquinoa" or "lupinelupine" in your dataframe. I think the pattern you're using is inccorect. This works : filter_at(df, vars(contains("Pair")), any_vars(str_detect(., pattern = "quinoa|lupine")))







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 9 at 9:39









        Ismail MüllerIsmail Müller

        1164




        1164



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55075782%2ffilter-at-selected-columns-with-multiple-str-detect-patterns%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved