[R] A coding question involving variable assignments
ecatchpole
e.catchpole at adfa.edu.au
Fri Aug 12 04:48:54 CEST 2005
Sorry, I don't follow. What's wrong with this?
Ted.
> set.seed(99)
> x <- replicate(5,replicate(10,sum(rnorm(rpois(1,10)))))
> set.seed(99)
> mx <- replicate(5,replicate(10,max(rnorm(rpois(1,10)))))
> x
[,1] [,2] [,3] [,4] [,5]
[1,] -2.0071674 -7.0883335 -0.03766649 2.6859415 -5.4685172
[2,] -4.7211799 2.4177121 -0.92575948 -7.2201952 -2.5969177
[3,] 0.2325584 -0.1790635 -3.17988580 -2.0249829 1.6994276
[4,] -1.7738725 1.5836438 5.06193854 -5.4798269 -2.4363479
[5,] -3.0394562 2.8859440 2.67993750 5.0534413 0.6560877
[6,] 6.2436591 -4.0226431 1.97545757 -1.5641548 4.0443831
[7,] 0.4641453 -10.4417831 1.08048629 2.4675178 -5.5114109
[8,] 1.1570728 -3.6081361 1.37858782 0.3534015 1.8282236
[9,] 4.3988625 3.0692562 -0.69898483 -1.6882952 -1.1548913
[10,] -3.7288105 -1.4455309 5.80146323 -6.1962790 -1.3698381
> mx
[,1] [,2] [,3] [,4] [,5]
[1,] 0.4896243 1.4110132 0.7329387 3.2700493 1.861891
[2,] 1.0989215 1.6215407 1.5980779 2.2921963 1.417614
[3,] 1.4000518 1.4867612 1.0130372 0.5686142 1.442630
[4,] 0.5981696 2.0916016 2.0894395 0.9760749 1.419316
[5,] 1.0066032 1.8084703 1.6556502 2.1431458 2.393037
[6,] 2.7329641 1.8689793 1.1494738 1.2899945 1.702919
[7,] 0.5851713 0.6224785 2.4466643 1.1955567 0.951106
[8,] 1.3850466 0.9305735 1.4003689 1.5209779 1.864211
[9,] 1.8645760 1.1958389 0.9270208 0.4971312 1.576020
[10,] 1.5889265 1.0253490 4.6865908 0.9852816 1.032410
On 12/08/05 12:17, xpRt.wannabe wrote,:
> Ted and List,
>
> In your code that produced 'mx', you dropped sum() from my original
> code though. As a result, the 10 x 5 max's are of the same value.
> Unfortunately, that's not what I need.
>
>
> On 8/11/05, ecatchpole <e.catchpole at adfa.edu.au> wrote:
>>On 12/08/05 05:55, xpRt.wannabe wrote,:
>>>Dear List,
>>>
>>>I have the following code that does what I want:
>>>
>>>x <- replicate(5,replicate(10,sum(rnorm(rpois(1,10)))))
>>>
>>>How might one change it such that the maximum value generated by
>>>rnorm(rpois(1,10)) can be retrieved for later use?
>>set.seed(99)
>>x <- replicate(5,replicate(10,sum(rnorm(rpois(1,10)))))
>>set.seed(99)
>>mx <- replicate(5,replicate(10,max(rnorm(rpois(1,10)))))
>>
>>should work?
>>
>>Ted.
>>--
>>Dr E.A. Catchpole
>>Visiting Fellow
>>Univ of New South Wales at ADFA, Canberra, Australia
>>and University of Kent, Canterbury, England
>>- www.ma.adfa.edu.au/~eac
>>- fax: +61 2 6268 8786
>>- ph: +61 2 6268 8895
>>
--
Dr E.A. Catchpole
Visiting Fellow
Univ of New South Wales at ADFA, Canberra, Australia
and University of Kent, Canterbury, England
- www.ma.adfa.edu.au/~eac
- fax: +61 2 6268 8786
- ph: +61 2 6268 8895
More information about the R-help
mailing list