[R] array loop

Petr PIKAL petr.pikal at precheza.cz
Wed Aug 1 09:23:16 CEST 2007


Hi

"Dong GUO ¹ù¶«" <guo.dong99 at gmail.com> napsal dne 31.07.2007 15:27:35:

> Thanks, Petr.
> 
> I changed the equation mark from "=" to "<-", then, it works fine. Dont 
know 
> what difference it has made between the "=" and "<-"..

from help page

The operators <- and = assign into the environment in which they are 
evaluated. The operator<- can be used anywhere, whereas the operator = is 
only allowed at the top level (e.g., in the complete expression typed at 
the command prompt) or as one of the subexpressions in a braced list of 
expressions. 

Although I do not fully understand where I can use <- and where =, to be 
on safe side I use <- everywhere when I want to do assignment of some 
value(s).

Regards

Petr

> 
> Regards,
> Dong 

> On 7/31/07, Petr PIKAL <petr.pikal at precheza.cz> wrote:
> Hi
> 
> as you say that the computing is part of a function than the best way to
> see what is hapenning is to use
> 
> debug(your.function)
> 
> see ?debug for options.
> 
> Regards
> 
> Petr
> petr.pikal at precheza.cz
> 
> r-help-bounces at stat.math.ethz.ch napsal dne 31.07.2007 00:11:00:
> 
> > Dear all,
> >
> > here are two arrays: region(26,31,8), nation(8) 
> >
> > I tried to get a new array, say, giGi(26,31,8)
> >
> > giGi <- array(0,dim = c(region_dim))
> >
> > for (i in (1:region_dim[3]))
> > {
> > giGi[,,i] = region[,,i]-nation[,i]
> >
> > }
> >
> > As the above is part of function, but results shows only giGi[,,1] has
> the
> > right answers, all the others (giGi[,,2],..giGi[..8]) are zeros. I 
have
> > checked array of region and nation, they are not zeros at all.... 
> >
> > when I do manually, it is not the case, giGi has meanful numbers.
> >
> > can some one tell me the trick in this process??
> >
> > Many thanks in advance.
> > Dong
> >
> >    [[alternative HTML version deleted]] 
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch 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.



More information about the R-help mailing list