OneBite.Dev - Coding blog in a bite size

find the average of all elements in an array in R

Code snippet on how to find the average of all elements in an array in R

  sum(myArray) / length(myArray)

This code calculates the average of all elements in an array in R. The code starts with the ‘sum()’ function, which will add up all the elements in the array ‘myArray’. The output of that is then divided by the ‘length()’ function, which will count the number of elements in the array. Finally, the output of the division is the average of all elements in the array.

r