dplyr::summary根据另一列max提取值

dplyr::summary根据另一列max提取值,r,dplyr,R,Dplyr,基于以下可复制代码,如何根据max(最少员工)有条件地添加Address列: dat\u url% 总结( 横过(其中(是数值的)&!以(“最小”)开头),平均值, 跨越(c(“员工名称”、“SicCodes”),~toString(.x)), LeastNEmployees=最大值(LeastNEmployees)) 这里有一个方法可以使用条件来完成 a <- dat %>% left_join(df, c('EmployerSize' = 'EmployerSize'))

基于以下可复制代码,如何根据
max(最少员工)
有条件地添加
Address
列:

dat\u url%
总结(
横过(其中(是数值的)&!以(“最小”)开头),平均值,
跨越(c(“员工名称”、“SicCodes”),~toString(.x)),
LeastNEmployees=最大值(LeastNEmployees))

这里有一个方法可以使用
条件来完成

a <- dat %>% 
  left_join(df, c('EmployerSize' = 'EmployerSize')) %>% 
  group_by(ResponsiblePerson) %>% 
  summarize(
    across(where(is.numeric) & !starts_with("Least"), mean),
    across(c("EmployerName","SicCodes"), ~toString(.x)),
    LeastNEmployees = max(LeastNEmployees),
    Address = Address[which(LeastNEmployees == max(LeastNEmployees))])
a%
左联合(df,c('EmployerSize'='EmployerSize'))%>%
组员(负责人)%>%
总结(
横过(其中(是数值的)&!以(“最小”)开头),平均值,
跨越(c(“员工名称”、“SicCodes”),~toString(.x)),
LeastNEmployees=最大值(LeastNEmployees),
地址=地址[其中(LeastNEmployees==max(LeastNEmployees))]
a <- dat %>% 
  left_join(df, c('EmployerSize' = 'EmployerSize')) %>% 
  group_by(ResponsiblePerson) %>% 
  summarize(
    across(where(is.numeric) & !starts_with("Least"), mean),
    across(c("EmployerName","SicCodes"), ~toString(.x)),
    LeastNEmployees = max(LeastNEmployees),
    Address = Address[which(LeastNEmployees == max(LeastNEmployees))])