Error msg with group_by

Hi. I don't understand the error msg:

library(dplyr)
df <- data.frame(x=c("D","D","D","D","E","E","E","E"), y=c(5,3,4,2,4,3,5,2))
data %>%
dplyr::group_by(x) %>%
summarize(avg_value = mean(y))

Error in UseMethod("group_by_") :
no applicable method for 'group_by_' applied to an object of class "function"
Calls: %>% ... summarize -> -> group_by.default -> group_by_
In addition: Warning message:
group_by_() is deprecated as of dplyr 0.7.0.
Please use group_by() instead.

Thank you.

You care calling data but your data frame is called df.

library(dplyr)
df <- data.frame(x=c("D","D","D","D","E","E","E","E"), y=c(5,3,4,2,4,3,5,2))

df %>%
  group_by(x) %>%
  summarise(avg_value = mean(y))

# A tibble: 2 x 2
  x     avg_value
* <chr>     <dbl>
1 D           3.5
2 E           3.5
1 Like

Well that was embarrassing!

Thank you.

2 Likes