Something like this is what I would do
library(tidyverse)
df_example <- tibble::tribble(
~ID, ~A, ~B, ~C, ~D,
1L, 0.2, 23.3, 2.3, 4.32,
2L, 2.3, 2.4, 0, 1,
3L, 23.3, 1.3, 23, 3.44,
2L, 34.2, 33, 56.5, 76.5,
1L, 0.3, 76.4, 3.2, 78.5
)
df_example %>%
group_by(ID) %>%
summarise(lenght_vector = c_across(cols = c(A:D)) %>% length(),
sum_vector = c_across(cols = c(A:D)) %>% sum(),
mean_error = sum_vector/lenght_vector,
MSE = mean_error %>% sqrt())
#> `summarise()` ungrouping output (override with `.groups` argument)
#> # A tibble: 3 x 5
#> ID lenght_vector sum_vector mean_error MSE
#> <int> <int> <dbl> <dbl> <dbl>
#> 1 1 8 189. 23.6 4.85
#> 2 2 8 206. 25.7 5.07
#> 3 3 4 51.0 12.8 3.57
Created on 2020-11-11 by the reprex package (v0.3.0)