In this type of situation, I usually add the new items to a list at each
step of the loop. The end result is a list of lists. This keeps all of
the objects in their original format. It also allows me to use lapply to
extract the components that I need when creating summaries or for further
analysis.
i.e.
storage _ as.list()
for (i in 1:1000){ do all my stuff
storage[[i]] _ list(all my new objects)
}
getcomp _ function{mylist}
return(mylist$myresult)
}
lapply(storage, getcomp)
At 05:57 AM 4/22/2003 -0700, Spencer Graves wrote:
Comments inline:
Stefano Sofia wrote:
Dear Splus users,
I do need some advices about vectors definition and storage.
I am building a quite big procedure where many vectors and matrices are
involved. Within this procedure there is a for loop (of length n), and
because of at each step I want to store all the vectors and matrices, I
use the following structure:
array(NA, dim = c(n, number of rows, 1)) or array(NA, dim = c(number of rows,
1)) for the vectors and array(NA, dim = c(n, number of rows, number of
columns)) or array(NA, dim =
c(number of rows, number of columns)) for the matrices.
For some reasons it happens that vectors are stored not correctly: not
vertically (for example of dimension 13 by 1) but horizontally (i.e. of
dimension 1 by 13).
In the function below reported, the vector E4iniz is correctly evaluated
(dimension (14 by 1), but with
E6iniz <- E4iniz[(2:14), ]
E6iniz <- E4iniz[(2:14), ,drop=F ]
# drop=T, the default, reduces the dimension of the array
I hope this solves the problem without me reading the rest of your code.
Best Wishes,
spencer graves
<snip>
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu. To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message: unsubscribe s-news
Naomi S. Altman 814-865-3791 (voice)
Associate Professor
Dept. of Statistics 814-863-7114 (fax)
Penn State University 814-865-1348 (Statistics)
University Park, PA 16802-2111
|