[R] Generate random percentages and placing vectors

David Winsemius dwinsemius at comcast.net
Wed Oct 27 17:12:22 CEST 2010


On Oct 27, 2010, at 11:02 AM, Aaron Lee wrote:

> Hello everyone,
>
> I have two questions:
>
> 1.) I would like to generate random percentages that add up to 100.  
> For
> example, if I need 5 percentages, I would obtain something like: 20,  
> 30, 40,
> 5, 5. Is there some way to do this in R?
>
> 2.) I would like to insert vectors of specified length into a larger  
> vector
> of specified length randomly, and fill the gaps with zeroes. For  
> example, if
> I have 3 vectors of length 3, 2, and 2 with values and I would like to
> randomly place them into a vector of length 25 made of 0's.

You need to specify the order of placement and whether over-writing is  
allowed. If overwriting is not allowed then after the first is placed  
the allowable positions may shrink in odd ways.

>
> Thank you in advance!
>


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list