[R] Ref: Variable scope or function behaviour or array reassign

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Oct 26 08:33:26 CEST 2004


Kunal Shetty wrote:
> 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)
> 


Please don't use double spacing.


You want to return a list:

foo1 <- function(.....){
	.....
	return(list(newXmean = newx, newYmean = newy))
}

and call the resulting objects as follows:

foo2 <- function(.....){
	new <- foo1(.....)
	print(new$newXmean)
	print(new$newYmean)

}


Uwe Ligges




More information about the R-help mailing list