I need some help to solve the following problem :
I have a 47x42 data.frame
with non null values in the upper-diag part, and I need to create a new data.frame based on this one where the value is defined by :
new_tab[i,j] <- 1/2 * previous_tab[i,j] + 1/2 * mean(adjacent_cells_of(i,j))
For example a smaller data.frame could be :
structure(list(X0 = c(10000L, 10000L, 10000L, 10000L, 10000L),
X1 = c(2842L, 2842L, 2842L, 2842L, NA), X2 = c(1743L, 1743L,
1743L, NA, NA), X3 = c(1144L, 1144L, NA, NA, NA), X4 = c(838L,
NA, NA, NA, NA)), .Names = c("X0", "X1", "X2", "X3", "X4"
), row.names = 15:19, class = "data.frame")
X0 X1 X2 X3 X4
15 10000 2842 1743 1144 838
16 10000 2842 1743 1144 838
17 10000 2842 1743 NA NA
18 10000 2842 NA NA NA
19 10000 NA NA NA NA
My problem is how can i define "mean of adjacent cells" giving that for [1,1]
value there are only 3 adjacent cells and for [2,2]
there are 8 values.
The new value of [2,2]
should be :
1/2* 2842 +1/16*(10000+2842+1743+1743+1743+2842+10000+10000)
To put it in other words, it's a kind of smoothing values of my original data.frame by the next values. I don't know if i'm clear enough, but i can elaborate if needed.
Thanks for your help.