s-news
[Top] [All Lists]

Re: vectors definition and storage

To: Spencer Graves <spencer.graves@PDF.COM>, Stefano Sofia <stefano.sofia@usa.net>
Subject: Re: vectors definition and storage
From: Naomi Altman <naomi@stat.psu.edu>
Date: Tue, 22 Apr 2003 10:50:57 -0400
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <3EA53C57.805@pdf.com>
References: <116HDVisE2896S08.1050999510@uwdvg008.cms.usa.net>
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



<Prev in Thread] Current Thread [Next in Thread>