What do you mean by 'passing an array reference' and 'dereferencing' and
what do you mean by an 'R script'?  What language(s) are you accustomed to?

If you mean 'passing an array value' to an 'R function', you just use the
argument name.  Since R uses call-by-value (modulo the substitute mechanism,
which as a beginner you should avoid), modifying the array within your
function does not modify the global value.  Normally you'd return the value,
e.g.

> ar <- array( 1:12,c(3,4))
> ar
     [,1] [,2] [,3] [,4]
[1,]    1    4    7   10
[2,]    2    5    8   11
[3,]    3    6    9   12

> sum12 <- function(a) { a[1,] + a[2,] }
> sum12(ar)
[1]  3  9 15 21                << returned value

If you want to *modify* the array ar, you should do something like this:

> ar[1,] <- sum12(ar)

> ar[1,] <- sum12(ar)
> ar
     [,1] [,2] [,3] [,4]
[1,]    3    9   15   21
[2,]    2    5    8   11
[3,]    3    6    9   12

Does this answer your question?

           -s
On Thu, Jul 16, 2009 at 9:04 AM, xin liu <liux...@yahoo.com> wrote:

>
> Hi, All,
>
> I passed an array reference to the R script and do not know how to do
> dereferencing in the R script. Anybody has some suggestion?
>
> Many thanks
>
> ______________________________________________
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to