I have a large dataframe which contain columns like this:
df <- data.frame(W0 = 1,
Response = 1,
HighResponse = 1,
Response.W0 = 1,
HighResponse.W0 =1)
Now, in a for loop, I want to select a column based on whether they contain a specified string- Response, W0, HighResponse. My method of selecting the column is:
x <- dplyr::select(df, contains("HighResponse.W0")) #this works
x <- dplyr::select(df, contains("HighResponse")) #doesn't work. Selects HighResponse and HighResponse.W0
x <- dplyr::select(df, contains("Response")) #doesn't work. Selects Response, HighResponse, Response.W0, HighResponse.W0
x <- dplyr::select(df, contains("W0")) #doesn't work. Selects W0, Response.W0, HighResponse.W0
How can I modify my column selection method, so that it only selects exact string? For ex, select only W0 or Response not the other matching strings.
map