[R] do calculations as defined by a string / expandmathematical statements in R

Daniel Nordlund djnordlund at frontier.com
Wed Oct 5 23:25:41 CEST 2011


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Martin Batholdy
> Sent: Wednesday, October 05, 2011 2:10 PM
> To: R Help
> Subject: Re: [R] do calculations as defined by a string /
> expandmathematical statements in R
> 
> Thanks for all the suggestions!
> 
> 
> 
> Perhaps my post was not clear enough.
> 
> apply(array,1:2,sum)/dim(array)[3]
> 
> and
> 
> # reproducible example
> x <- 1:1000
> dim(x)<-rep(10,3)
> # code
> apply(x,1:2,sum)
> 
> 
> would give me the mean over one whole dimension, right?
> The problem with that is, that I just want to calculate the mean over a
> subset of t (where t is the 4th dimension of the array).
> And the range of this subset should be easily changeable.
> 
> 
> So for example I have 4D array:
> 
> x <- 1:10000
> dim(x)<-rep(10,4)
> 
> Now I would like to average the 3D array(x,y,z) in the 4th dimension (t)
> from t_start = a to t_end = b.
> I don't want to average the whole 3D array.
> 


I don't have specific advice to address your question, but I do have an observation on this series of posts.  It is often the case that people new to R try to program like they would if they were using C, or SAS, or ... whatever they are used to.  I can't help but think that if you provided some context for what your tasks are you might find that someone on the list is working in the same area and could provide advice tailored to what you need to do.  Why, there might even be a package or two that already provide the functionality that you need.  So, broadly speaking, what do these multidimensional arrays represent and what are you trying to do with them?


Dan

Daniel Nordlund
Bothell, WA USA



More information about the R-help mailing list