The attempted problem is to group by column A and create a flag for every row in the group if any of its values in column B are over 100. The example table looks like this-
Column A | Column B |
---|---|
NYC | 95 |
NYC | 98 |
BOS | 88 |
BOS | 101 |
BOS | 67 |
MIA | 90 |
And for the resulting df to look like this-
Column A | Column B | fg |
---|---|---|
NYC | 95 | |
NYC | 98 | |
BOS | 88 | 1 |
BOS | 101 | 1 |
BOS | 67 | 1 |
MIA | 90 |
Even if one of the values is over 100, I would like the fg column to return 1 for all the rows.
The attempted code was as follows-
df %>% group_by(Column A) %>% mutate(fg = ifelse(Column B >= 100 ,1, ''))
but this seems to error out. What other method could work?