Generating New Columns by Group But Getting Unknown Results from World Bank Data

Solution 1:

Have you got NA's in your variable column?

If so, try this to get the sum ignoring missing values:

df %>%
  group_by(group) %>%
  mutate(sum = sum(variable, na.rm=TRUE)) %>%
  ungroup()