... In fact, on my computer, the pmax construction took longer. I would guess that's due to the data.frame construction. Nevertheless, the comment is still germane.
Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." H. Gilbert Welch On Fri, Jan 10, 2014 at 1:03 PM, Bert Gunter <bgun...@gene.com> wrote: > It probably doesn't make much difference in this small example, but > maybe it's worth noting that **if possible** (it typically is not), > things can be speeded up by generating all the random numbers at once > then applying a vectorized operation to the entire ensemble. In this > case, this becomes: > > ran <- do.call(pmax,data.frame(matrix(rnorm(1e6),nr=1000))) > > pmax() is the vectorized operation. The do.call(...,data.frame(..))) > construction must be used to satisfy the argument list requirements > for pmax and do.call. > > Cheers, > Bert > > > Bert Gunter > Genentech Nonclinical Biostatistics > (650) 467-7374 > > "Data is not information. Information is not knowledge. And knowledge > is certainly not wisdom." > H. Gilbert Welch > > > > > On Fri, Jan 10, 2014 at 12:31 PM, arun <smartpink...@yahoo.com> wrote: >> Hi, >> >> May be this helps: >> set.seed(42) >> vec1 <- sapply(1:1000,function(x) max(rnorm(1000,0,1))) >> #or >> set.seed(42) >> vec2 <- replicate(1000,max(rnorm(1000,0,1))) >> identical(vec1,vec2) >> #[1] TRUE >> >> set.seed(598) >> res <- sample(vec1,100,replace=FALSE) >> >> max(res) >> #[1] 4.408794 >> A.K. >> >> Hello I need some help in programming: >> >> I want to after take a rnorm(1000,0,1) sample want to save the >> max of it in a vector, this was difficult to me, then I need to repeat >> this process 1000 times, so I shall have 1000 maximum from the normal of >> samples of size 1000. >> Then I want to sample from this maximum series a new sample, this time of >> size 100. >> >> I drive a programm: >> >> sample<-rnorm(1000,0,1) >> for(i in 1:length(sample)){ >> maxim<-vector(mode="numeric",length(sample)) >> maxim[i]<-max(sample) >> } >> >> then my result was a vector with n-1 zeroes and the last one >> value was a maximum. I think it took the last value, but I don't know >> how to repair it. >> >> I need most help, thanks >> >> >> ______________________________________________ >> R-help@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. ______________________________________________ R-help@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.