multi-dimension array manipulation R -


I'm sorry, but I can not find any way to change every 0 in the dimension of 3 dimensions that are columns.

Thank you. So, for example, suppose I have this array

  j, 1 [, 1] [, 2] [1,] 0 6 [2,] 1 5 [3, ] 2 2, 2 [, 1] [, 2] [1,] 11 0 [2,] 14 12 [3,] 0 14, 3 [, 1] [, 2] [1,] 1922 [2] ], 20 23 [3,] 21 24   

I want

  j, 1 [, 1] [, 2] [1,] 1 6 [2,] 1 5 [3,] 2 2, 2 [, 1] [, 2] [1,] 11 26/3 [2,] 14 12 [3,] 25/3 14 ,, 3 [ , 1]], 2222 [2], 20 23 [3,] 21 24    

for it.

Getting started with the following data:

  arr & lt; - Array (0: 5, dim = C (4,3,2)), 1 [, 1] [, 2] [, 3] [1,] 0 4 2 [2,] 1 5 3 [3, ] [4,] 3 1 5, 2 [, 1] [, 2] [, 3] [1,] 0 4 2 [2,] 1 5 3 [3,] 2 0 4 [4,] 3 1 5   

You can:

  apply (arr, c (2,3), function (v) {v [v ==] 0] & lt; - Mean (v); v})   

returns:

 , 1 [, 1] [, 2] [, 3] [1,] 1.5 4.0 2 [2,] 1.0 5.0 3 [3,] 2.0 2.5 4 [4,] 3.0 1.0 5, 2 [, 1] [, 2] [, 3] [1,] 1.5 4.0 2 [2,] 1 .0 5.0 3 [3,] 2.0 2.5 4 [4,] 3.0 1.0 5    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -