I'd like to summarise sales data grouping by city and adding a column where "1" means "the city has at least one store that sells more than 100" and "0" means "otherwise".
This is an approximation of what I'm trying:
library(dplyr)
my_data <- tibble(city = c("City 1","City 1","City 2","City 1"),
store = c("mc donalds","starbucks","target","jp licks"),
sales = c(300,200,3000,80),
sales_higher_than_100 = c(1,1,1,0))
my_data %>%
group_by(city) %>%
summarise(has_stores_that_sell_more_than_100 = sum(sales_higher_than_100))
# A tibble: 2 x 2
city has_stores_that_sell_more_than_100
<chr> <dbl>
1 City 1 2
2 City 2 1
However, instead of summation I'd like to report a value of 1 for "City 1" like this:
# A tibble: 2 x 2
city has_stores_that_sell_more_than_100
<chr> <dbl>
1 City 1 1
2 City 2 1
In other words, I wonder how to instruct dplyr to find if one or more of the rows of City N meet a condition instead of counting each of the rows that meet the condition for City N.