Chris
Chris

Reputation: 2071

proposicional logic in string matches combination

I have a problem in R, when I want to do a combination of string matches, like:

X <- colnames(df[substr(colnames(df),start=1,stop=3) == "PEC" | substr(colnames(df),start=1,stop=5) == "PRE1_" & substr(colnames(df),start=1,stop=5) != "PEC3"])

X is going to be the df of independent variables for a future linear regression. X is composed by PECZZZ, PRE1_ZZZ where the Z character is any number between 0 and 9. PEC3 is de dependent variable. So as the first string match will have PEC3 as calling PEC implies PEC3, I'm using the third string match to delete it. However, the results for PEC3 in the string matches above are:

TRUE | FALSE & FALSE = TRUE

Why? If TRUE | FALSE = TRUE, and TRUE & FALSE = FALSE. Or it doesn't follow the left-to-right common order rule?

Upvotes: 0

Views: 28

Answers (1)

iod
iod

Reputation: 7592

In R & precedes |. See for full list of operators and their order here: https://stat.ethz.ch/R-manual/R-patched/library/base/html/Syntax.html

Upvotes: 1

Related Questions