[R] Maximum of Maximum
Bert Gunter
gunter.berton at gene.com
Fri Jan 10 22:03:40 CET 2014
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 <smartpink111 at 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 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.
More information about the R-help
mailing list