Thanks for the help! However, for the code in #2, it seems to just randomly split up the vectors. I would still like to keep the integrity of each vector.
For example: if v1 = (1,2,3) v2 = (4,5,6) output = (0,0,0,1,2,3,0,0,0,0,4,5,6,0,0,0,0,0,0,0,0,0,0,0,0) - which has a specified length of 25 With v1 and v2 inserted in at random locations. On Wed, Oct 27, 2010 at 10:25 AM, Jonathan P Daily <jda...@usgs.gov> wrote: > > 1) > rands <- runif(5) > rands <- rands/sum(rands)*100 > > 2) > # assume vectors are v1, v2, etc. > v_all <- c(v1, v2, ...) > v_len <- length(v_all) > > output <- rep(0,25) > output[sample(1:25, v_len)] <- v_all > > -------------------------------------- > Jonathan P. Daily > Technician - USGS Leetown Science Center > 11649 Leetown Road > Kearneysville WV, 25430 > (304) 724-4480 > "Is the room still a room when its empty? Does the room, > the thing itself have purpose? Or do we, what's the word... imbue it." > - Jubal Early, Firefly > > > From: Aaron Lee <aaron.zl....@gmail.com> To: r-help@r-project.org Date: > 10/27/2010 > 11:06 AM Subject: [R] Generate random percentages and placing vectors Sent > by: r-help-boun...@r-project.org > ------------------------------ > > > > 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. > > Thank you in advance! > > -Aaron > > [[alternative HTML version deleted]] > > ______________________________________________ > 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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > > > [[alternative HTML version deleted]] ______________________________________________ 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.