Reputation:
I want to have the year column selected too in the output but I dont understand how to add another column in the select statement. The column I want to select is a simple column named "Year".
Following is the code I am trying to use but it gives me an error. The select_if condition is correct because if I do not add the "select("Year")" line the code works fine. Please help
Subset <-df %>%
select("Year") & select_if(grepl("Apple", names(.)))
Upvotes: 0
Views: 284
Reputation: 66425
library(dplyr)
mtcars %>%
select(cyl, contains("gea")) %>%
head()
cyl gear
Mazda RX4 6 4
Mazda RX4 Wag 6 4
Datsun 710 4 4
Hornet 4 Drive 6 3
Hornet Sportabout 8 3
Valiant 6 3
Upvotes: 4