How to select data by column/header name


#1

Hi,

I have over 300 columns with different header names. Is there a way I can select only those columns containing "A" or "B"?

Here is what I have tried that works:

newdf <- select(olddf, contains("A"))

This code works, but I am trying to incorporate 2 conditions within the above statement. For example the below does not work:

newdf <- select(olddf, contains("A" | "B"))

Thank you


#2

This will work:

select(iris, c(contains(".Length"), contains(".Width")))

#3

Thank you for the prompt response!