[R] writing function

Wu Gong ghowoo at gmail.com
Thu May 20 22:22:44 CEST 2010


## Create a function to assign a series of values to a list of objects
## The assign function can only assign one value (could be a vector) to a
name
## Set the environment to be global, otherwise the objects can't be used
outside the function
## List objects that have been created

toto <- function(x,y) {
	for (i in x:y){
		assign(paste("tot", i, sep=""), i*2, envir = .GlobalEnv)
		}}
toto(3,7)
ls(pattern = "^tot.$")

-----
A R learner.
-- 
View this message in context: http://r.789695.n4.nabble.com/writing-function-tp2224781p2225249.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list