Skip to main content
added 37 characters in body
Source Link
akuiper
  • 215.7k
  • 33
  • 362
  • 379

You need a double stage groupby, firstly groupby metro and state get the count and then groupby metro and filter out count that is not equal to the max count within each metro:

data1 <- data %>% group_by(metro, State) %>% mutate(count = n()) %>% 
                  group_by(metro) %>% filter(count == max(count))

nrow(data1)

You need a double stage groupby, firstly groupby metro and state get the count and then groupby metro and filter out count that is not equal to the max count within each metro:

data %>% group_by(metro, State) %>% mutate(count = n()) %>% 
         group_by(metro) %>% filter(count == max(count))

You need a double stage groupby, firstly groupby metro and state get the count and then groupby metro and filter out count that is not equal to the max count within each metro:

data1 <- data %>% group_by(metro, State) %>% mutate(count = n()) %>% 
                  group_by(metro) %>% filter(count == max(count))

nrow(data1)
added 143 characters in body
Source Link
akuiper
  • 215.7k
  • 33
  • 362
  • 379

You need a double stage groupby, firstly groupby metro and state get the count and then groupby metro and filter out count that is not equal to the max count within each metro:

data %>% group_by(metro, State) %>% filtermutate(count === maxn(count))

# Source:%>% local 
 data frame [2 x 3]
# Groups: metro [2]
#
#    group_by(metro ) State%>% filter(count
#   <fctr> <fctr> <int>
# 1      A     OH   703
# 2      B     GA == 1453max(count))
data %>% group_by(metro) %>% filter(count == max(count))

# Source: local data frame [2 x 3]
# Groups: metro [2]
#
#    metro  State count
#   <fctr> <fctr> <int>
# 1      A     OH   703
# 2      B     GA  1453

You need a double stage groupby, firstly groupby metro and state get the count and then groupby metro and filter out count that is not equal to the max count within each metro:

data %>% group_by(metro, State) %>% mutate(count = n()) %>%  
         group_by(metro) %>% filter(count == max(count))
Source Link
akuiper
  • 215.7k
  • 33
  • 362
  • 379

data %>% group_by(metro) %>% filter(count == max(count))

# Source: local data frame [2 x 3]
# Groups: metro [2]
#
#    metro  State count
#   <fctr> <fctr> <int>
# 1      A     OH   703
# 2      B     GA  1453