How to make a program in R that provides the result below?

Asked

Viewed 71 times

-1

I have a question regarding to make an algorithm that provides the result of the equation below. inserir a descrição da imagem aqui

1 answer

1

The question equation can be programmed as follows.

media_amos <- function(z, na.rm = TRUE){
  if(na.rm) z[is.na(z)] <- 0
  n <- nrow(z)
  cmb <- choose(n, 2)
  z[row(z) == col(z)] <- 0
  sum(z)/(2*cmb)
}

x <- matrix(1:36, nrow = 6)

media_amos(x)
#[1] 18.5

mean(x)
#[1] 18.5

Browser other questions tagged

You are not signed in. Login or sign up in order to post.