I have a data.frame like the following:
GROUP OGS valMax
1 Group1 A 81.5
2 Group1 B 87.1
3 Group1 C 66.2
4 Group2 D 7.2
5 Group2 E 5.3
6 Group2 F 10.1
I am trying to create new column "groupMax" by filling it with max of "valMax". The expected output is:
GROUP OGS valMax groupMax
1 Group1 A 81.5 87.1
2 Group1 B 87.1 87.1
3 Group1 C 66.2 87.1
4 Group2 D 7.2 10.1
5 Group2 E 5.3 10.1
6 Group2 F 10.1 10.1
I did the following:
library(tidyverse)
library(magrittr)
df %>% group_by(GROUP) %>% mutate(groupMax = max(valMax))
The error I get is,
Error in mutate(groupMax = max(valMax)) : object 'valMax' not found
Is the data masking not working here?
Thanks in advance.