Testo visibile solo ai moderatori e all'autore del post faccio da me:
apply(data[2:4], MARGIN = 1, FUN = mean)
apply(data[5:7], MARGIN = 1, FUN = mean)
apply(data[10:12], MARGIN = 1, FUN = mean)
MARGIN = 1 applica la funzione mean per riga
Da
https://redoakstrategic.com/applyfunctions/:
The apply function in R is used as a fast and simple alternative to loops. It allows users to apply a function to a vector or data frame by row, by column or to the entire data frame.