[R] Assign variables in a loop to a list

Márcio Resende mresendeufv at yahoo.com.br
Wed Dec 9 18:13:22 CET 2009


Dear R helpers,
I am new in R and I am having trouble with a function.
I am proggraming a genetic analysis and there is a script that generates a
lot of different matrix, for example x,y and z.
And what I am trying to do is to loop the same script for different
variables the user will define in the function. Therefore the matrix x, y
and z are going to be created for each variable

myfun <- function(...){    #the variables in (...) for example ("DAP",
"Vol")
Vec = matrix(c(...))
for (i in seq(along = Vec)){
... ##generates x, y and z
# The scripts are not here because they are big

assign(paste("x",i,sep=""),x)
assign(paste("y",i,sep=""),y)  #this generates x1,y1,z1, x2, y2, and z2 for
the example with two variables
assign(paste("z",i,sep=""),z)
}

####Here is the step of my doubt where I can´t solve
#### I want to assign those variables in a list function

structure(list(...), class = "genotype") ## In the example it would be

##structure(list(varX1 = x1, varX2 = x2, varY1 = y1, varY2 = y2, varZ1 = z1,
varZ2 = z2), class = "genotype")

} #end of function

However I don´t know how to assign those variables in this list because I
don´t know how many variables will the user declare

I am not sure if I was clear, I know it is hard without the whole script,
but I think it wouldn´t make any difference. It could be considered 3
randomly matrix generated each time (each loop).

Thank you very much for the help and for the time dispended



-- 
View this message in context: http://n4.nabble.com/Assign-variables-in-a-loop-to-a-list-tp956207p956207.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list