Perhaps you have NA values in your data. If so, these can be ignored by setting na.rm = TRUE in your call to mean().
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
d <- data.frame(id=c(1,2,3, 1, 2, 3, 1, 2, 3, 1), x=c(1,2,3,4,3,4,5,2,3,2) )
Stats <- d %>% group_by(id) %>% summarize(Avg = mean(x))
Stats
#> # A tibble: 3 x 2
#> id Avg
#> <dbl> <dbl>
#> 1 1 3
#> 2 2 2.33
#> 3 3 3.33
#with NA
d <- data.frame(id=c(1,2,3, 1, 2, 3, 1, 2, 3, 1), x=c(1,NA,3,NA,3,NA,5,2,3,2) )
Stats <- d %>% group_by(id) %>% summarize(Avg = mean(x))
Stats
#> # A tibble: 3 x 2
#> id Avg
#> <dbl> <dbl>
#> 1 1 NA
#> 2 2 NA
#> 3 3 NA
#With NA and na.rm = TRUE
d <- data.frame(id=c(1,2,3, 1, 2, 3, 1, 2, 3, 1), x=c(1,NA,3,NA,3,NA,5,2,3,2) )
Stats <- d %>% group_by(id) %>% summarize(Avg = mean(x, na.rm = TRUE))
Stats
#> # A tibble: 3 x 2
#> id Avg
#> <dbl> <dbl>
#> 1 1 2.67
#> 2 2 2.5
#> 3 3 3
Created on 2019-07-12 by the reprex package (v0.2.1)