[R] How to complete this code

Adams, Jean jvadams at usgs.gov
Mon Apr 13 14:24:04 CEST 2015


You will likely get more help answering your question if you provide
reproducible code of a simple example of your situation.

Jean

On Fri, Apr 10, 2015 at 3:42 PM, Mahdiyeh Erfaniyan <
mahdiyeh.erfaniyan at gmail.com> wrote:

> Hi,
>
>
> Consider the line below:
>
>
>
> for(r in a)for (s in a) x=rbind(x,apply(replicate(1000,V(r,s)),1,mean))
>
>
>
> V is a vector of (n-1) variables calculated by some rule and is a functions
> of (r,s).  So the line above produces 1000 replicates of V for each (r,s),
> puts them in a matrix, calculates the mean of them, and finally puts the
> means for all (r,s) in a matrix. So the produced matrix, x, is the mean of
> (n-1) V 's for each possible value of (r,s) in each row. Now for simplicity
> fix (r,s) in just one point and let n=5. So in each replicate we have only
> one V which is a vector consisted of 4 variables. Name the elements of V as
> U1, U2, U3 and U4. Then we can let
>
> V(i) = [U1i , U2i , U3i , U4i]
>
>
>
> which shows each row of V produced per replicate (i=1,2,...,1000).
> Therefore we can say
>
>
>
> x=[x1 , x2 , x3 , x4]
>
>
>
> which is the vector of means calculated at the end. Now what I need is to
> first calculate the vector below per replicate (i=1,...,1000):
>
>
>
> Er(i) = [ |Ui1-x1| , |Ui2-x2| , |Ui3-x3| , |Ui4-x4| ]
>
>
>
> where |A| shows the absolute value of A. Then I should calculate mean of
> Er(i) 's and put the result in a vector. I just don't know how I can
> calculate Er(i) 's in the given line above. On the other words, I don't
> know where I should add the required code in the given line. Thanks for any
> help in advance!
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list