r - Replace 0 with data from another array -
i want replace 0 (missing data) data array.
both data has 2013~1995 january ice sheet data, , want analyze temperature data (in column 3), 4464 temperatures data.
partial data looks this: erinjan[,,1]
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1 ,] 21 10 0.0 0.0 0.0 0 0.0 0 [2 ,] 21 11 0.0 0.0 0.0 0 0.0 0 [3 ,] 21 12 -16.3 867.4 0.0 0 0.0 0 [4 ,] 21 13 -16.4 867.5 6.9 81 63.2 0 [5 ,] 21 14 -16.5 867.2 7.6 83 63.0 0 [6 ,] 21 15 -16.5 867.1 7.9 84 63.0 0 [7 ,] 21 16 0.0 867.1 8.0 86 62.0 0 [8 ,] 21 17 -16.3 867.0 8.4 87 62.0 0 [9 ,] 21 18 0.0 866.9 8.3 85 62.0 0 and harryjan[,,1] looks like:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1 ,] 21 10 -12.4 877.6 2.5 52 444.0 9.1 [2 ,] 21 11 -12.6 877.6 3.0 55 444.0 9.1 [3 ,] 21 12 -12.9 877.5 3.8 52 444.0 9.1 [4 ,] 21 13 -13.0 877.5 3.6 53 444.0 9.1 [5 ,] 21 14 -12.9 877.3 3.3 51 444.0 9.1 [6 ,] 21 15 -13.0 877.3 4.1 53 444.0 9.1 [7 ,] 21 16 -13.2 877.1 3.6 53 444.0 9.1 [8 ,] 21 17 -13.4 877.3 3.3 45 444.0 9.1 [9 ,] 21 18 -13.4 877.3 3.6 48 444.0 9.1 both array has same format , same type of data above. goal replace erinjan[,3,1] missing data harryjan[,3,1] , on. example, erinjan[1,3,1] missing data, need replace harryjan[1,3,1]. (0 replaced -12.4.)
if can code this:
(i in 1: 19){ if erinjan[,3,i] == 0 { replace value using harryjan } else { nothing } } is possible? not sure command should use. replace?
i'd appreciate help.
if understand question, this:
erinjan[erinjan == 0] <- harryjan[erinjan == 0] would make replacement across whole matrix. not sure how columns arranged, if pull out column 3s, should able same replacement variable.
i believe work column 3 only:
erinjan[,3,][erinjan[,3,]==0] = harryjan[,3,][erinjan[,3,]==0] this works indexing elements of first array equal 0 , using same indices pull values second array.
if find stuff in square brackets confusing, here way break out in 2 steps:
janind = which(erinjan[,3,]==0) erinjan[,3,][janind] = harryjan[,3,][janind]
Comments
Post a Comment