[R] Multidimensional Array: local averaging without knowing number of dimensions
Sebastian Schubert
schubert.seb at googlemail.com
Wed Apr 18 17:47:35 CEST 2012
Hi,
I want to access and modify a multi dimensional array but without
knowing the exact number of dimensions.
Basically. I want something like that for every i (except boundaries of
course):
field[i, ...] <- (field[i, ...] + field[i+1, ...] + field[i-1, ...])/3
In principle, ... should just represent the other dimension, for a 1
dimensional field:
field[i] <- (field[i] + field[i+1] + field[i-1])/3
For a 2 dimensional field
field[i, ] <- (field[i, ] + field[i+1, ] + field[i-1, ])/3
For a 3 dimensional field
field[i,,] <- (field[i,,] + field[i+1,,] + field[i-1,,])/3
and so on.
Is there a way to formulate this without writing it for every number of
dimension?
Cheers
Sebastian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 262 bytes
Desc: OpenPGP digital signature
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120418/c82909b3/attachment.bin>
More information about the R-help
mailing list