I am trying to create a function in R. The function should find outliers from a matrix using z score. The function should have two arguments as input (x which is a matrix and zs which is an integer). For each raw of the matrix, the function should calculate the zscore for each element and if zscore is bigger than zs
or smaller than -zs
, then the function should print that element. I know that I can use:
z<- (x-mean(x))/sd(x) or z<- scale(x)
for the calculations of z score but as I am a beginner in programming, I find it difficult to solve the problem because of the matrix.