[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-help
Subject:    [R] Multidimensional Array: local averaging without knowing number of dimensions
From:       Sebastian Schubert <schubert.seb () googlemail ! com>
Date:       2012-04-18 15:47:35
Message-ID: 4F8EE217.3010209 () googlemail ! com
[Download RAW message or body]

[Attachment #2 (multipart/signed)]


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


["signature.asc" (application/pgp-signature)]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic