I'd like to replace the na values in my df column with the most common value by group
#Ex:
df <- data.frame(Home_Abbr = c('PHI', 'PHI', 'DAL', 'PHI'),
Home_City = c('Philadelphia', 'Philadelphia', 'Dallas', NULL))
#Desired Result
Home_Abbr Home_City
PHI Philadelphia
PHI Philadelphia
DAL Dallas
PHI Philadelphia
Here is what I've tried so far:
df <- df %>%
group_by(Home_Abbr) %>%
mutate(Home_City = names(which.max(table(Home_City))))
But when I run this I get a 'Can't combine NULL and non NULL results' Error.