Uwe Ligges
           thank you for u prompt reply
        my problem was in step3
        where my function returns two  different arrays.
Yes i did try returning an object from the array.
but the problem became...i tired returning the two arrays in a dataframe  such as

newXY <- data.frame("newXmean"=newx, "newYmean" =newy)

         

but in the calling function or loop;  i wasn't able to access each individual array as an array; from the assigned object.

    Output <- algoResult(x,y,xNA,yNA,ctr); Output

     print(Output)   ?? 
     print(Output[1])
     print(Output$newy)

hence was trying to assign the global arrays within the function  itself without bothering to return any object...

   any help on this..     

regards
Kunal



Uwe Ligges <ligges@statistik.uni-dortmund.de> wrote:
> Kunal Shetty wrote:
> 
> > Dear R- helpers
> > 
> > Following a draft structure of the R script for which I am facing problem
> > 
> > Step 1
> > x <-   of type array with original values
> > y <-   of type array  with original values
> > 
> > 
> > Step 2
> > 
> > for (ctr in 1:10) {
> > 
> > # my problem here the both x and y still show the original values from step 1
> > # in spite of making changes to the old values of the arrays x and y in the function
> >    function (x,y)  ???
> > 
> >     }
> > 
> > 
> > step3
> > 
> > 
> > output < - function(parX,parY){
> > 
> >           Variables for New X and Y
> > 	newx <- array(parX, dim=c(1,length(parX)))
> > 	newy <- array(parY, dim=c(1,length(parY)))
> > 
> >                 # make some calculation and updated some arrays element in the newX and   # #newY
> > 
> > 
> >                        # finally assign the global  original values x and y with newX and newY
> >                         
> >                        x<- newx
> > 	           y<- newy
> >                       # if print here I can see the new values
> >                   
> >                        # but when the function gets called the second time  the original values of 
> >            #  x and y get called hence failing my motive of passing update values of                  #the arrays to the function each time   ???
> > }
> > I believe there something to deal with env or new.env.... but never could get the concept of the variable scope.....where the fact with the function the x and y get updated but while calling from the main loop the x and y are pointing to old values
> > 
> >   also I am keen to know as to is there a way to clear the array of old values and reasign new values..or the <- operator take care of it by overwriting
> > 
> > regards
> > Kunal
> > 
> > ______________________________________________
> > R-help@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
> 
> 
> I don't understand your question completely. Anyway, I guess you have 
> missed the point that you can pass arguments to a function and that you
> can return an object (e.g. a list of other objects) from the function 
> (please read "An Introduction to R" for more details).
> Assign the value returned by a function it to an object in the calling 
> function. In most circumstances, don't think too much about accessing 
> environments, because you don't want to do it! The mechanisms mentioned
> above are sufficient in most circumstances.
> 
> Uwe Ligges


Uwe Ligges <ligges@statistik.uni-dortmund.de> wrote:
> Kunal Shetty wrote:
> 
> > Dear R- helpers
> > 
> > Following a draft structure of the R script for which I am facing problem
> > 
> > Step 1
> > x <-   of type array with original values
> > y <-   of type array  with original values
> > 
> > 
> > Step 2
> > 
> > for (ctr in 1:10) {
> > 
> > # my problem here the both x and y still show the original values from step 1
> > # in spite of making changes to the old values of the arrays x and y in the function
> >    function (x,y)  ???
> > 
> >     }
> > 
> > 
> > step3
> > 
> > 
> > output < - function(parX,parY){
> > 
> >           Variables for New X and Y
> > 	newx <- array(parX, dim=c(1,length(parX)))
> > 	newy <- array(parY, dim=c(1,length(parY)))
> > 
> >                 # make some calculation and updated some arrays element in the newX and   # #newY
> > 
> > 
> >                        # finally assign the global  original values x and y with newX and newY
> >                         
> >                        x<- newx
> > 	           y<- newy
> >                       # if print here I can see the new values
> >                   
> >                        # but when the function gets called the second time  the original values of 
> >            #  x and y get called hence failing my motive of passing update values of                  #the arrays to the function each time   ???
> > }
> > I believe there something to deal with env or new.env.... but never could get the concept of the variable scope.....where the fact with the function the x and y get updated but while calling from the main loop the x and y are pointing to old values
> > 
> >   also I am keen to know as to is there a way to clear the array of old values and reasign new values..or the <- operator take care of it by overwriting
> > 
> > regards
> > Kunal
> > 
> > ______________________________________________
> > R-help@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
> 
> 
> I don't understand your question completely. Anyway, I guess you have 
> missed the point that you can pass arguments to a function and that you
> can return an object (e.g. a list of other objects) from the function 
> (please read "An Introduction to R" for more details).
> Assign the value returned by a function it to an object in the calling 
> function. In most circumstances, don't think too much about accessing 
> environments, because you don't want to do it! The mechanisms mentioned
> above are sufficient in most circumstances.
> 
> Uwe Ligges


