An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120630/3a6aebe1/attachment.pl>
loop in list
3 messages · solafah bh, Greg Snow, arun
Instead of a loop you can use the replicate or lapply functions which
will create lists for you.
otherwise you can start with an empty list (mylist <- list() )
then add to the list in each iteration of the loop:
for(i in 1:10) {
mylist[[i]] <- myfunction(i)
}
On Sat, Jun 30, 2012 at 1:34 PM, solafah bh <solafahbh at yahoo.com> wrote:
Hello
I have a loop to sample 20 samples and I want to put them in one list, how I can make this??
Regards
Sulafah
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
Hi,
Try this,
list1<-list()
vec<-rnorm(15,25)
for(i in 1:20)
{
list1[[i]]<-sample(vec,replace=FALSE)
}
list1
[[1]]
?[1] 24.28594 25.05309 25.48962 24.71479 22.48122 25.41300 25.26129 25.15602
?[9] 24.91442 23.65078 26.84776 24.85934 25.00111 24.16320 27.05351
[[2]]
?[1] 24.91442 24.28594 25.05309 24.16320 24.71479 22.48122 25.26129 26.84776
?[9] 25.00111 25.41300 27.05351 25.48962 25.15602 24.85934 23.65078
-------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
A.K.
----- Original Message -----
From: solafah bh <solafahbh at yahoo.com>
To: R help mailing list <r-help at r-project.org>
Cc:
Sent: Saturday, June 30, 2012 3:34 PM
Subject: [R] loop in list
Hello
I have a loop to sample 20 samples and I want to put them in one list, how I can make this??
?
Regards
Sulafah
??? [[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.