How to use the apply function to find the mean of array entry in the same position in R

Uddin

For the following array

z <- array(1:12, dim = c(2,2,3))
 z
, , 1

     [,1] [,2]
[1,]    1    3
[2,]    2    4

, , 2

     [,1] [,2]
[1,]    5    7
[2,]    6    8

, , 3

     [,1] [,2]
[1,]    9   11
[2,]   10   12

I would like to construct a 2x2 matrix by taking the mean value of the same position entry. My first entry is the average of 1,5,9 and the second entry is the average of 3,7,11 the third entry is the average of 2,6,10 and fourth entry is the average of 4,8,12. Any help is appreciated.

akrun

We specify the MARGIN as 1 and 2, and apply the mean using apply

apply(z, c(1,2), mean)
#     [,1] [,2]
#[1,]    5    7
#[2,]    6    8

Or specify one MARGIN and use rowMeans

apply(z, 1, rowMeans)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to find the mean of same cells in an array of Breeze Matrices in spark scala?

From Dev

How to use growth rates with apply function instead of a loop in R

From Dev

How to use ‘apply’ with function that returns wrong dimensions (R)

From Dev

How to use apply group of function in R to calculate mean of values with plus delimiter

From Dev

R : How to use apply in this case to speed up the function?

From Dev

How to apply the same function to several variables in R?

From Dev

How to use a function to find the mean based upon conditions in the data

From Dev

How to use ~ function notation using apply-family functions in R?

From Dev

How do I apply the same function to each value in an array of dicts?

From Dev

how to apply same function to multiple dataframes in R

From Dev

How to use array_intersect to find the same files?

From Dev

How to apply/loop the same function to a group of similar objects in R

From Dev

How use apply for each matrix in 3-d array in R

From Dev

R: How to use margins of a 3-dimensional array as individual arguments to the same function?

From Dev

How to use apply family functions on an array and a matrix instead of a for loop in R?

From Dev

Error in use index to find entry in an array in python

From Dev

How to use jquery .show() to apply a function in the same parent element?

From Dev

How to apply function by groups in array in R?

From Dev

how to use apply function to take no names column mean?

From Dev

How to sequentially/separately apply the same function on array of objects?

From Dev

R: How to use apply function in below code instead of loop

From Dev

How to use apply function with list of functions with multiple argument in r?

From Dev

R How to use function "Length with condition" at period.apply?

From Dev

How to use row number inside apply function in R

From Dev

How to use multiple columns as inputs for apply function in R

From Dev

How to use apply function from R to normalize data frame?

From Dev

Find Pairs in Array with same mean as the Array

From Dev

How to use group by and a conditional mean at the same time in R?

From Dev

How to find the position of same rows from one 2D array to another 2D array?

Related Related

  1. 1

    How to find the mean of same cells in an array of Breeze Matrices in spark scala?

  2. 2

    How to use growth rates with apply function instead of a loop in R

  3. 3

    How to use ‘apply’ with function that returns wrong dimensions (R)

  4. 4

    How to use apply group of function in R to calculate mean of values with plus delimiter

  5. 5

    R : How to use apply in this case to speed up the function?

  6. 6

    How to apply the same function to several variables in R?

  7. 7

    How to use a function to find the mean based upon conditions in the data

  8. 8

    How to use ~ function notation using apply-family functions in R?

  9. 9

    How do I apply the same function to each value in an array of dicts?

  10. 10

    how to apply same function to multiple dataframes in R

  11. 11

    How to use array_intersect to find the same files?

  12. 12

    How to apply/loop the same function to a group of similar objects in R

  13. 13

    How use apply for each matrix in 3-d array in R

  14. 14

    R: How to use margins of a 3-dimensional array as individual arguments to the same function?

  15. 15

    How to use apply family functions on an array and a matrix instead of a for loop in R?

  16. 16

    Error in use index to find entry in an array in python

  17. 17

    How to use jquery .show() to apply a function in the same parent element?

  18. 18

    How to apply function by groups in array in R?

  19. 19

    how to use apply function to take no names column mean?

  20. 20

    How to sequentially/separately apply the same function on array of objects?

  21. 21

    R: How to use apply function in below code instead of loop

  22. 22

    How to use apply function with list of functions with multiple argument in r?

  23. 23

    R How to use function "Length with condition" at period.apply?

  24. 24

    How to use row number inside apply function in R

  25. 25

    How to use multiple columns as inputs for apply function in R

  26. 26

    How to use apply function from R to normalize data frame?

  27. 27

    Find Pairs in Array with same mean as the Array

  28. 28

    How to use group by and a conditional mean at the same time in R?

  29. 29

    How to find the position of same rows from one 2D array to another 2D array?

HotTag

Archive